Skip to content

Instantly share code, notes, and snippets.

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