In my store I have isLoading: boolean value which is false and changed to true when request to server starts and after respose or on error it changed back to false. I select it in container class and pass to component as property like this:
@Component({
template: `<some-component [isLoading]="isLoading"></some-component>`
})
class SomeContainer() {
private isLoading: Observable<boolean>;
constructor(private store: Store<IStore>) {
this.isLoading = store.select(isLoadingSelector);
}
}
And I would like to use it for some conditional content:
class SomeComponent {
@Input() private isLoading: Observable<boolean>;
...
}
<div>
<span *ngIf="isLoading">Loading</span>
<span *ngIf="!isLoading">Some data</span>
</div>
but isLoading is Observable and I have to get boolean value for expected working of this logic. The solution I found is getting value in class like this:
private ngOnInit():void {
this.isLoading.subscribe((value) => this.isLoadingBoolean = value);
}
and use isLoadingBoolean in template.
But it looks tricky. Is there better way to solve this issue (maybe is way to use async pipe with *ngIf)?
*ngIf="!(isLoading | async)"? - chrigu