zoukankan      html  css  js  c++  java
  • ng2学习--pipe使用

    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 { }
  • 相关阅读:
    dos
    admin package
    ant 调用系统环境变量
    idea6+tomcat5.5开发web程序
    VFloppy
    ant中classpath
    Velocity用户手册
    ant中 Tomcat的任务调用(包括deploy,undeploy,load,start,stop等)
    [转]aidl高级应用篇
    Android NDK开发环境安装(OK版)
  • 原文地址:https://www.cnblogs.com/lishidefengchen/p/6485834.html
Copyright © 2011-2022 走看看