Angular *ngIf variable with async pipe multiple conditions

后端 未结 4 740
再見小時候
再見小時候 2021-02-12 05:31

There\'s quite good doc of using *ngIf in Angular: https://angular.io/api/common/NgIf But, is that possible to have *ngIf async variable and multiple checks on that? Something l

4条回答
  •  误落风尘
    2021-02-12 06:14

    Here's the alternative version, with a little bit cleaner template:

    
      
    {{ user | json }}
    No users found

    Note that we use users$ | async 2 times. That will work if you add shareReplay() operator to user$ Observable:

      public users$: Observable = this.someService.getUsers()
        .pipe(shareReplay());
    

    That way, inner template will be able to access last value of the Observable and display the results.

    You can try it out on stackblitz.

提交回复
热议问题