Could anyone help me with the issue. In a <div>
element, I want to display the element when an Observable is evaluated available, and also display the content of the Observable value.
Please see the code below:
html
<div *ngIf="message$ | async">{{message$ | async}}</div>
<button (click)="onclick()">button</button>
ts
message$ = new Subject<string>();
ngOnInit() { this.message$.next(null);}
onclick() { this.message$.next("test");}
When I click on the button, the <div>
element is displayed because the *ngIf="message$ | async"
is evaluated true, while the template interpolation value {{message$ | async}}
has no value.
This is where I don't understand. Anyone know about it please help to explain, thanks. {{message$ | async}} dosen't work
P.S. I tried two other method to make it work (but still don't understand above mentioned problem):
1: use the as syntax: {{msg}};
2: use BehaviorSubject: message$ = new BehaviorSubject(null); it works