0

I have tried this code bellow and it doesn't work

this.users$ = this.userService.get();
<span *ngIf="!users$ | async">No data</span>
3
  • !(users$ | async) Commented Dec 4, 2020 at 21:43
  • It's working :), TNX Commented Dec 6, 2020 at 10:57
  • I've expanded my comment into an answer and explanation, if you care to accept it. Commented Dec 7, 2020 at 12:03

1 Answer 1

1

This is the result of misunderstanding the negation operator, ! in template syntax.

In the provided code sample, !users$ | async examines the users$ observable for nullness and then applies the async pipe, making the observable's emitted value available to the template.

Because that observable is the result of an api call, it can never be null. You want to examine the emitted value from that observable for nullness, so you instead need to wrap the entire expression in parenthesis !(users$ | async).

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.