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 { }
  • 相关阅读:
    HDU 1022 Train Problem I
    HDU 1702 ACboy needs your help again!
    HDU 1294 Rooted Trees Problem
    HDU 1027 Ignatius and the Princess II
    HDU 3398 String
    HDU 1709 The Balance
    HDU 2152 Fruit
    HDU 1398 Square Coins
    HDU 3571 N-dimensional Sphere
    HDU 2451 Simple Addition Expression
  • 原文地址:https://www.cnblogs.com/lishidefengchen/p/6485834.html
Copyright © 2011-2022 走看看