Created
October 2, 2017 18:30
-
-
Save AustinMatherne/5d18f8116178d519e97fac8029145670 to your computer and use it in GitHub Desktop.
ngIf Data Binding
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 {Observable} from 'rxjs/Observable'; | |
import {defer} from 'rxjs/observable/defer'; | |
import {of} from 'rxjs/observable/of'; | |
@Component({ | |
selector: 'my-app', | |
template: ` | |
<ng-container *ngIf="data$ | async as data"> <!-- single subscription --> | |
<div> | |
Data: {{data}} <!-- 0.4431839407652687 --> | |
</div> | |
<div> | |
Data: {{data}} <!-- 0.4431839407652687 --> | |
</div> | |
</ng-container> | |
`, | |
}) | |
export class App { | |
data$: Observable<number> = defer(() => of(Math.random())); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment