码迷,mamicode.com
首页 > 其他好文 > 详细

[Angular] New async 'as' syntax and ngIf.. else

时间:2017-08-11 10:55:05      阅读:145      评论:0      收藏:0      [点我收藏+]

标签:syn   instead   ...   syntax   length   src   expr   ble   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

标签:syn   instead   ...   syntax   length   src   expr   ble   else   

原文地址:http://www.cnblogs.com/Answer1215/p/7343101.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!