Created
April 3, 2020 13:12
-
-
Save Qarun-Qadir-Bissoondial/098118d65c82af3e7fd42efbefdbb463 to your computer and use it in GitHub Desktop.
Pipes Demo - Async Pipe
This file contains 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 { HttpClient } from '@angular/common/http'; | |
import { Observable } from 'rxjs'; | |
@Component({ | |
selector: 'app-async-with-pipe', | |
template: ` | |
<p *ngIf = 'character | async as char; else loading'> | |
{{char | json}} | |
</p> | |
<ng-template #loading> | |
<p>Loading using pipe...</p> | |
</ng-template> | |
`, | |
styleUrls: [] | |
}) | |
export class AsyncWithPipeComponent { | |
character: Observable<any>; | |
constructor(private http: HttpClient) { | |
this.character = this.http.get('https://swapi.co/api/people/1'); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment