Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save Qarun-Qadir-Bissoondial/4a1e1a56a3b4d54d540323205566915e to your computer and use it in GitHub Desktop.
Save Qarun-Qadir-Bissoondial/4a1e1a56a3b4d54d540323205566915e to your computer and use it in GitHub Desktop.
Pipes Demo - Async without Pipe
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