ng2学习--pipe使用
2024-10-21 14:42:02
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 { }
最新文章
- 安卓SQLite常见错误
- Devexpress TextAnnotation
- oracle学习之表空间
- AIM Tech Round 3 (Div. 2) A
- [转] POJ图论入门
- Mac下使用sublime text 2开发Python
- Linux内存管理学习笔记--物理内存分配
- auto space advisor
- vmware克隆Centos6.7虚拟机网卡无法启动问题
- vue中如何获取后台数据
- 新概念英语(1-43)Hurry up!
- js处理数字加后缀w
- linux基础练习题(2)
- SVN常用命令说明
- 使用shiro框架,解决跳转页面出现404的问题
- Java Map 接口
- 百度地图在移动端下click无效的解决方案
- 偏前端-vue.js学习之路初级(二)组件化构建
- 关于HttpURLConnection/HttpsURLConnection请求出现了io.filenotfoundexception:url的解决方法
- java instanceof方法
热门文章
- DP小合集
- CQOI2018做题记录
- 对存在JavaScript隐式类型转换的四种情况的总结
- RPM包及其管理 rpm命令
- JVM插庄之一:JVM字节码增强技术介绍及入门示例
- node包管理工具nvm
- static和final的区别
- 第五篇 elasticsearch express插入数据
- linux切割文件【split命令详解】
- 报错:Caused by: org.hibernate.id.IdentifierGenerationException: ids for this class must be manually assigned before calling save(): cn.itcast.bos.domain.base.SubArea