首页 > 代码库 > [Angular] New async 'as' syntax and ngIf.. else
[Angular] New async 'as' syntax and ngIf.. else
From Anuglar v4 above, we are able to using ‘as‘ with async pipe. This allow as using ‘new variable‘ instead of subscribe to observable.
We also able to use ‘else‘ with ‘*ngIf‘, else taks a ‘template‘ which will be displayed when the if expression is not matched.
<ng-template #loading> <div class="message"> <img src="/img/loading.svg" alt="loading..."> Fetching meals... </div> </ng-template> <div *ngIf="meals$ | async as meals; else loading;"> <div class="message" *ngIf="!meals.length"> <img src="/img/face.svg" alt="no meals"> No meals, add new meal to add </div> <!-- meal ngFor --> </div>
[Angular] New async 'as' syntax and ngIf.. else
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。