October 2017
Intermediate to advanced
280 pages
6h 50m
English
We're already familiar with the concept of observables from the previous chapters. We can say that an Observable object allows us to subscribe to the emission of a sequence of values, for instance:
let observer = Observable.create(observer => {
setInterval(() => {
observer.next(new Date().getTime());
}, 1000);
});
observer.subscribe(date => console.log(date));
Once we subscribe to Observable, it will start emitting values each second, which will be printed in the console. Let's combine this snippet with component definition and implement a simple timer:
// ch8/async_pipe/app.ts @Component({ selector: 'timer' }) class Timer { username: string; timer: Observable<number>; constructor() { let counter = 0; this.timer ...Read now
Unlock full access