We use our custom pipe the same way we use built-in pipes.(自定义Pipe和API里自带的Pipe使用方式一致)

We must include our pipe in the declarations array of the AppModule.(Pipe要起作用的话,需要把它放到AppModule中declarations属性数组中。)

如果你正在按照《迈向Angular 2: 基于TypeScirpt的高性能SPA框架》学习的话,你会发现,Componet中没有pipes这个属性,而书中的例子就有!

我写文档这个时间(2017/3/1),从官方下载的quick-start里面,就不再支持这样的写法了,而正如我开头”红字“所写的那样,Pipe需要放在app.component.ts这个文件中的AppModule类的declarations属性中,

declarations这个属性的值是一个数组,我们先把我们自定义的或api中的pipe导入到这个文件中(例如:import { lowercasePipe } from './app.lowercase';),然后再把pipe添加到数组中。

import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import { lowercasePipe } from './app.lowercase';//这个是我自己写的pipe @NgModule({
imports: [BrowserModule],
declarations: [AppComponent, lowercasePipe],
bootstrap: [AppComponent]
})
export class AppModule { }

最新文章

  1. 安卓SQLite常见错误
  2. Devexpress TextAnnotation
  3. oracle学习之表空间
  4. AIM Tech Round 3 (Div. 2) A
  5. [转] POJ图论入门
  6. Mac下使用sublime text 2开发Python
  7. Linux内存管理学习笔记--物理内存分配
  8. auto space advisor
  9. vmware克隆Centos6.7虚拟机网卡无法启动问题
  10. vue中如何获取后台数据
  11. 新概念英语(1-43)Hurry up!
  12. js处理数字加后缀w
  13. linux基础练习题(2)
  14. SVN常用命令说明
  15. 使用shiro框架,解决跳转页面出现404的问题
  16. Java Map 接口
  17. 百度地图在移动端下click无效的解决方案
  18. 偏前端-vue.js学习之路初级(二)组件化构建
  19. 关于HttpURLConnection/HttpsURLConnection请求出现了io.filenotfoundexception:url的解决方法
  20. java instanceof方法

热门文章

  1. DP小合集
  2. CQOI2018做题记录
  3. 对存在JavaScript隐式类型转换的四种情况的总结
  4. RPM包及其管理 rpm命令
  5. JVM插庄之一:JVM字节码增强技术介绍及入门示例
  6. node包管理工具nvm
  7. static和final的区别
  8. 第五篇 elasticsearch express插入数据
  9. linux切割文件【split命令详解】
  10. 报错:Caused by: org.hibernate.id.IdentifierGenerationException: ids for this class must be manually assigned before calling save(): cn.itcast.bos.domain.base.SubArea