October 2017
Intermediate to advanced
280 pages
6h 50m
English
Angular's AsyncPipe transform method accepts an Observable object or a promise as an argument. Once the argument pushes a value (that is, the promise has been resolved or the subscribe callback of Observable is invoked), AsyncPipe will return it as a result. Let's take a look at the following example:
// ch8/async-pipe/app.ts
@Component({
selector: 'greeting',
template: 'Hello {{ greetingPromise | async }}'
})
class Greeting {
greetingPromise = new Promise<string>(resolve => this.resolve = resolve);
resolve: Function;
constructor() {
setTimeout(_ => {
this.resolve('Foobar!');
}, 3000);
}
}
Here, we define an Angular component that has two properties, that is, greetingPromise of the Promise<string> type and resolve ...
Read now
Unlock full access