You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Dec 4, 2017. It is now read-only.
As we’ve talked about previously, Observables must be subscribed to in order to handle the data they produce,
327
-
and must be unsubscribed from in order to clean up the resources they have used. You’ve gone through how to
328
-
subscribe to an Observable, get its data and provide that data through a variable in your class. There is also
329
-
a built-in pipe available for use with template syntax to manage Observable subscriptions called the Async Pipe.
330
-
When used in a template, the async pipe will subscribe to the Observable or evaluate a Promise, receive its
331
-
emitted values and dispose of its subscription once the component is destroyed. The pipe also ties into Change Detection,
332
-
so that when new values are produced, the component is marked for detection in order to determine whether it’s changes
333
-
need to be reflected in your user interface. This is useful as it reduces the amount of boilerplate you need when setting
334
-
up data to be fetched and provided to your template. We’ll learn later about cases where using an async pipe is beneficial
335
-
versus managing your own subscription manually.
336
-
337
-
Example: Fetching heroes using a service, subscribing/unsubscribing manually then removing the subscription and delegating responsibility to the async pipe. Another example would be showing hero details with multiple async pipes, but instead using a single subscription.
With many applications, user input is required to initiate or complete an action. Whether it be logging in or filling out
343
-
an information page, user data is another stream that needs to be handled. In contrast to template-driven forms where the
344
-
responsibility is on the developer to gather the pieces of data from the form, the model-driven/Reactive forms uses
345
-
Observables to easily provide a continuous stream of user input. By using the reactive approach, our form will be ready
346
-
to handle user input streams from form fields, as well as provide that form data seamlessly to another stream for
347
-
processing.
348
-
349
-
Example: Simple form that displays form status/value changes over time. Also displays creating an Observable from an existing event. valueChanges on individual field/entire form
350
-
351
-
Router
352
-
353
-
The browser URL is another stream of information. It provides you with a canonical link to the application view you are
354
-
displaying at any given moment, along with information about what data to display. The Angular Router uses the browser URL
355
-
to provide you with multiple streams that hook into the navigation process, URL data provided through your route
356
-
configuration, parameters provided for context and path information. These pieces of data are provided by the Router
357
-
through Observables, since we are certain that these streams happen in a continuous fashion as a user navigates throughout
0 commit comments