Created
June 27, 2016 07:03
-
-
Save tkssharma/d8843dd3aa0600ae0bcbb024f3118245 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import {Component} from '@angular/core'; | |
import {Observable} from 'rxjs/Observable'; | |
@Component({ | |
selector: 'app', | |
template: ` | |
<b>Angular 2 Component Using Observables!</b> | |
<div>Values: {{values.toString()}}</div> | |
<div>Errors? {{anyErrors}}</div> | |
<div>Finished? {{finished}}</div> | |
` | |
}) | |
export class App { | |
private data: Observable<Array<number>>; | |
private values: Array<number> = []; | |
private anyErrors: boolean; | |
private finished: boolean; | |
constructor() { | |
this.data = new Observable(observer => { | |
setTimeout(() => { | |
observer.next(42); | |
}, 1000); | |
setTimeout(() => { | |
observer.next(43); | |
}, 2000); | |
setTimeout(() => { | |
observer.complete(); | |
}, 3000); | |
}); | |
let subscription = this.data.subscribe( | |
value => this.values.push(value), | |
error => this.anyErrors = true, | |
() => this.finished = true | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I think line 15 should be
versus