PipeTransform不工作ionic2

时间:2017-02-25 05:35:48

标签: angular typescript ionic-framework pipe ionic2

我有一些改变单词的项目

  

示例:lang->语言

我想离子选项以大写的第一个字母显示所有项目

  

示例:author->作者

例如

author        Author
lang          Language
date          Date
loca          Location

mycode的

<ion-select [(ngModel)]="refine" (ionChange)="optionsFn(item, i);" >
        <ion-option [value]="item"  *ngFor="let item of totalfilter | mypipe;let i = index" >{{item["@NAME"]}}</ion-option>
      </ion-select>

mypipe.ts

       import { Pipe, PipeTransform } from '@angular/core';

    @Pipe({
        name: 'mypipe', pure: false
    })
    export class MyPipe implements PipeTransform {
  public posts;
public post;
      transform(items: any[]): any[] {
          if (items && items.length)
            this.posts = items.filter(it => it["@NAME"] =  it["@NAME"].replace('lang','language'));
            this.post = this.posts.filter(it => it["@NAME"] = it["@NAME"].charAt(0).toUpperCase()+ it["@NAME"].slice(1))

          return this.post;
        }

    }

无效,错误

  

无法读取未定义的属性“过滤器”

1 个答案:

答案 0 :(得分:1)

这样做:

import { Pipe, PipeTransform } from '@angular/core';

@Pipe({
    name: 'mypipe', pure: false
})
export class MyPipe implements PipeTransform {

    transform(items: any[]): any[] {
        if (items && items.length)
          return items.filter(it => it["@NAME"] = it["@NAME"].charAt(0).toUpperCase() + it["@NAME"].slice(1));
        return items;  
    }

}