async pipe
This is the documentation for Angular 6.
You can switch to the latest version Angular 10.
You can switch to the latest version Angular 10.
Unwraps a value from an asynchronous primitive.
The async
pipe subscribes to an Observable
or Promise
and returns the latest value it has emitted. When a new value is emitted, the async
pipe marks the component to be checked for changes. When the component gets destroyed, the async
pipe unsubscribes automatically to avoid potential memory leaks.
Source
<code>observable|async</code>
Time: {{ time | async }}
export class AppComponent {
time = new Observable<string>((observer: Observer<string>) => {
setInterval(() => observer.next(new Date().toString()), 1000);
});
}
Result
observable|async
Time: Sat Oct 10 2020 16:26:44 GMT+0300 (GMT+03:00)