[Angular] New async 'as' syntax and ngIf.. else
2023-09-14 08:59:18 时间
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 应用 [含懒加载]
- 前端必读3.0:如何在 Angular 中使用SpreadJS实现导入和导出 Excel 文件
- Angular HTTPClient API 在 SAP 电商云中的使用
- angular面试题及答案_angular面试
- angular 路由懒加载_angular路由
- orbital angular momentum_omnidirectional
- 【Angular教程】-组件通信|8月更文挑战
- 关于 Angular 工程文件 angular.json 里的 inlineCritical 属性
- Angular 项目多国语言设置
- Angular 项目中 angular.json builder 字段的可选项介绍
- Angular 2对 React:究竟孰优孰劣?
- angular.element方法汇总
- angular中使用路由和$location切换视图