First, how to use a build in pipe: <div class="pipe-example"> <label>Uppercase Pipe: {{ message | uppercase }}</label> </div> <div class="pipe-example"> <label>Lowercase Pipe: {{ message | lowercase…
For example you make a function to get rating; getRating(score: number): string { let rating: string; console.count('RatingPipe'); if(score > 249000){ rating = "Daniel Boone"; } else if(score > 200000){ rating = "Trail Guide"; }…
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…
以下为自定义过滤器 import { Pipe, PipeTransform, Injectable } from '@angular/core'; import { DomSanitizer} from '@angular/platform-browser'; @Pipe({ name: 'weekPipe' }) //数字转中文 export class WeekPipe implements PipeTransform { transform(value: any, args?: any)…
When using provider string tokens, there’s a chance they collide with other third-party tokens. Angular has with the concept of opaque tokens, that allow us to make whatever token we use unique, so we don’t run into collision problems. In this lesson…
In order to resolve a dependency, Angular’s DI uses type annotations. To make sure these types are preserved when transpiled to ES5, TypeScript emits metadata. In this lesson we’ll explore how the @Injectable decorator ensures metadata generation for…
目录 序言 变更检查机制 性能优化原理 性能优化方案 小结 参考 序言 本文将谈一谈 Angular 的性能优化,并且主要介绍与运行时相关的优化.在谈如何优化之前,首先我们需要明确什么样的页面是存在性能问题?好的性能的衡量指标是什么?性能优化背后的原理又是如何的?如果你对这些问题感兴趣,那么就请继续读下去. 变更检测机制 不同于网络传输优化,运行时优化更加关注于 Angular 的运行机制以及如何编码才能有效地避免性能问题(最佳实践).而要弄明白 Angular 的运行机制,首先需要理解它的变更…
本文转自:https://www.pocketdigi.com/20170209/1563.html 管道(Pipe)可以根据开发者的意愿将数据格式化,还可以多个管道串联. 纯管道(Pure Pipe)与非纯管道(Impure Pipe) 管道分纯管道(Pure Pipe)和非纯管道(Impure Pipe).默认情况下,管道都是纯的,在自定义管道声明时把pure标志置为false,就是非纯管道.如: @Pipe({ name: 'sexReform', pure:false }) 纯管道和非纯…
AngularJs 1.x 中使用filters来帮助我们转换templates中的输出,但在Angular2中使用的是pipes,以下展示Angular 1.x and Angular 2中filter和pipe的对比: Filter/Pipe Name Angular 1.x Angular 2 currency ✓ ✓ date ✓ ✓ uppercase ✓ ✓ json ✓ ✓ limitTo ✓ ✓ lowercase ✓ ✓ number ✓   orderBy ✓   filte…
原文地址 https://www.jianshu.com/p/22e0f95bcf24 什么是管道 每个应用开始的时候差不多都是一些简单任务:获取数据.转换它们,然后把它们显示给用户. 获取数据可能简单到创建一个局部变量就行,也可能复杂到从WebSocket中获取数据流.一旦取到数据,我们可以把它们原始值的toString结果直接推入视图中. 但这种做法很少能具备良好的用户体验. 比如,几乎每个人都更喜欢简单的日期格式,例如1988-04-15,而不是服务端传过来的原始字符串格式 —— Fri…