Created
April 3, 2020 13:02
-
-
Save Qarun-Qadir-Bissoondial/4a1e1a56a3b4d54d540323205566915e to your computer and use it in GitHub Desktop.
Pipes Demo - Async without 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'; | |
@Component({ | |
selector: 'app-async-without-pipe', | |
template: ` | |
<p *ngIf = 'dataLoaded; else loading'>{{character | json}}</p> | |
<ng-template #loading> | |
<p>Getting data from SWAPI...</p> | |
</ng-template> | |
`, | |
styleUrls: [] | |
}) | |
export class AsyncWithoutPipeComponent { | |
character: object; | |
dataLoaded: boolean = false; | |
constructor(private http: HttpClient) { | |
this.http.get(`https://swapi.co/api/people/1`).subscribe(char => { | |
this.character = char; | |
this.dataLoaded = true; | |
}) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment