Created
November 20, 2017 15:40
-
-
Save pglazkov/15f64a88e422e94114c57ce5d78bc729 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'; | |
import { SharedData } from '../shared-data'; | |
@Component({ | |
selector: 'app-main', | |
template: ` | |
<button (click)="loadData()">Load data</button> | |
<div *ngIf="sharedData.value | async; let data"> | |
<h3>Data:</h3> | |
<ul> | |
<li *ngFor="let item of data.items">{{ item }}</li> | |
</ul> | |
</div> | |
` | |
}) | |
export class MainComponent { | |
constructor(public sharedData: SharedData) { } | |
async loadData() { | |
let data = await this.loadDataFromHttpService().toPromise(); | |
this.sharedData.init(data); | |
} | |
private loadDataFromHttpService() { | |
// Simulate loading data from HTTP service | |
return Observable.of({ items: ['a', 'b', 'c']}).delay(2000); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment