Skip to content

Instantly share code, notes, and snippets.

@artlowel
Last active May 7, 2018 13:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save artlowel/1826582c47e11ff3cb01c8b0946de593 to your computer and use it in GitHub Desktop.
Save artlowel/1826582c47e11ff3cb01c8b0946de593 to your computer and use it in GitHub Desktop.
An example of how to use a RemoteData object in a component
@Component({
})
export class SomeComponent implements OnInit {
collections$: Observable<RemoteData<PaginatedList<Collection>>>;
constructor(
private cds: CollectionDataService,
) {}
ngOnInit(): void {
this.collections$ = this.cds.findAll();
}
}
<h3>Collections</h3>
<ng-container *ngVar="(collections$ | async) as collectionRD">
<p *ngIf="collectionRD?.isLoading">Loading…</p>
<p *ngIf="collectionRD?.hasFailed">Failed: {{collectionRD?.error?.message}}</p>
<ul *ngIf="collectionRD?.hasSucceeded">
<li *ngFor="let collection of collectionRD?.payload?.page">
{{collection.name}}<br>
<span class="text-muted">{{collection.shortDescription}}</span>
</li>
</ul>
</ng-container>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment