[Angular] Show a loading indicator in Angular using *ngIf/else, the as keyword and the async pipe

The network may be unreliable and loading data may take time. Thus it is important to give the user some feedback about what‘s going on as fast as possible. In this lesson we learn how to leverage the else block of the *ngIf directive to show a simple loading indicator.

    <div *ngIf="buttonClicked">
      <div *ngIf="person$ | async as person; else personLoading">
        Name: {{ person.name }} <br />
        Twitter: {{ person.twitter }}
      </div>
      <ng-template #personLoading>
        Loading person...
      </ng-template>
    </div>
时间: 2024-08-03 02:04:47

[Angular] Show a loading indicator in Angular using *ngIf/else, the as keyword and the async pipe的相关文章

[Angular] Show a Loading Indicator for Lazy Routes in Angular

We can easily code split and lazy load a route in Angular. However when the user then clicks that lazy loaded route, it make some time to actually fetch and run the JavaScript bundle. In this lesson we'll see how we can implement a loading indicator

[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 Router] Configure Your First Angular 2 Route

Using the Angular 2 router requires defining routes, passing them in to the RouterModule.forRoot and then importing the configured RouterModule into your main App Module. Use the Wiki Search as example project. Create a HomeComponent to contain every

[Angular 2] Rendering an Observable with the Async Pipe

Angular 2 templates use a special Async pipe to be able to render out Observables. This lesson covers the syntax used to create an Observable in Angular 2 and then to render it out in the template. import {Component} from 'angular2/core'; import {boo

Angular项目构建指南 - 不再为angular构建而犹豫不决(转)

如果你不知道什么是Angular或者根本没听说过,那么我接下来所说的对你来说毫无益处,不过如果你打算以后会接触Angular或者干脆要涨涨姿势~读下去还是有点用的. Angular和它之前所出现的其余前端框架最大的不同,在于它的核心不再是DOM,而是数据,是model.我们惯用的不管是单纯的jQuery还是MVC的Backbone,它们本质仍是让我们更方便更有条理的操作DOM,但是Angular不是.通过一系列魔术般的手法,它将一切的重心转移到数据上.以开发应用而不是操作节点的方式去开发Web,

[从 0 开始的 Angular 生活]No.38 实现一个 Angular Router 切换组件页面(一)

前言 今天是进入公司的第三天,为了能尽快投入项目与成为团队可用的战力,我正在努力啃官方文档学习 Angular 的知识,所以这一篇文章主要是记录我如何阅读官方文档后,实现这个非常基本的.带导航的网页应用. 需求 需求大概是这样的: 开一个新的 Angular 项目,并且一开始选择加入 Router 功能 根组件是 AppComponent ,然后下方有三个子组件分别是 page1 page2 page3 可以在 AppComponent 内点击连结切换到这三个页面 参考文档: 路由与导航 Rou

[Angular 2] Controlling Rx Subscriptions with Async Pipe and BehaviorSubjects

Each time you use the Async Pipe, you create a new subscription to the stream in the template. This can cause undesired behavior especially when network requests are involved. This lesson shows how to use a BehaviorSubject to observe the http stream

[Angular Router] Lazy loading Module with Auxiliary router

Found the way to handle Auxiliary router for lazy loading moudle and erge load module are different. In Erge loading, it is recommended to create a shell component, inside shell component you need to define the router-outlet for each Auxiliary routes

[Angular 2] A Simple Form in Angular 2

When you create a Form in Angular 2, you can easily get all the values from the Form using ControlGroup and Controls. Bind [ng-form-model] to the <form> form bind to ControlGoup Bind [ng-form-control] to the <input> input bind to Gontrol impor