[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

时间: 2024-11-08 22:15:46

[Angular] New async 'as' syntax and ngIf.. else的相关文章

[Angular] Bind async requests in your Angular template with the async pipe and the &quot;as&quot; keyword

Angular allows us to conveniently use the async pipe to automatically register to RxJS observables and render the result into the template once the request succeeds. This has some drawbacks, especially if we want to bind the same data in multiple par

[Angular 2] Template property syntax

This lesson covers using the [input] syntax to change an element property such as “hidden” or “content-editable”. Using properties eliminates the need for Angular 1’s old directives such as ng-show and ng-hide as you’re now able to directly access an

[Angular 2] Async Http

Async Pipe: The Asynce pipe receive a Promise or Observable as  input and subscribes to the input, evetually emitting the value(s) changes arrive. In the demo, the logic is fom the list component, we ask service to get Heros by calling Start War API,

[Angular 9] Built-in template syntax $any

The $any() type cast function Sometimes a binding expression triggers a type error during AOT compilation and it is not possible or difficult to fully specify the type. To silence the error, you can use the $any() cast function to cast the expression

Angular概念纵览

Conceptual Overview Template(模板): HTML with additional markup (就是增加了新的标记的HTML) Directive(指令): extend HTML with custom attributes and elements (给HTML增加自定义属性和元素) Model(模型): the data shown to the user in the view and with which the user interacts (与用户交互

Ultimate guide to learning AngularJS in one day

What is AngularJS? Angular is a client-side MVC/MVVM framework built in JavaScript, essential for modern single page web applications (and even websites). This post is a full end to end crash course from my experiences, advice and best practices I've

dfsdf

This project was bootstrapped with Create React App. Below you will find some information on how to perform common tasks. You can find the most recent version of this guide here. Updating to New Releases Create React App is divided into two packages:

(转)inspect — Inspect live objects

原文:https://docs.python.org/3/library/inspect.html 中文:https://www.rddoc.com/doc/Python/3.6.0/zh/library/inspect/?highlight=inspect The inspect module provides several useful functions to help get information about live objects such as modules, classes

协程概念

关键词:协程 栈帧 指令 切换 跳转 异步结果的等待.后继计算的保存. Coroutines are computer program components that generalize subroutines for non-preemptive multitasking, by allowing execution to be suspended and resumed. Coroutines are well-suited for implementing familiar progra