离子2创造管道

时间:2017-06-06 07:08:08

标签: angular ionic2

我正在尝试创建一个按字母顺序排列对象数组的管道。但是,它不起作用。

这是我的管道代码(.ts):

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

    /*
      Generated class for the AlplabeticOrdering pipe.

      See https://angular.io/docs/ts/latest/guide/pipes.html for more info on
      Angular 2 Pipes.
    */
    @Pipe({
      name: 'alplabetic-ordering'
    })
    @Injectable()
    export class AlplabeticOrdering {
      /*
        Takes a value and makes it lowercase.
       */
      transform(friendsName, args:any[]) {

        var frName=[];
        frName.push(friendsName);

        return frName.sort();
      }
    }

这里是我调用过滤器的html:

 <ion-item *ngFor="let f of dataArray | alplabetic-ordering:f;">

这是一段错误:

Unhandled Promise rejection: Template parse errors:
TypeError: Cannot read property 'toUpperCase' of undefined ("
  </ion-refresher> -->
<ion-list *ngIf="pageType == 1">
  <ion-item [ERROR ->]*ngFor="let f of dataArray | alplabetic-ordering:f;">
    <ion-avatar item-left (click)="viewFriendsP"): FriendsListing@5:12
Parser Error: Unexpected token -, expected identifier, keyword, or string at column 32 in [let f of dataArray | alplabetic-ordering:f;] in FriendsListing@5:12 (" == 1">
  <ion-item *ngFor="let f of dataArray | alplabetic-ordering:f;">
    <ion-avatar item-left [ERROR ->](click)="viewFriendsProfile()">
        <img [src]="f.imgURL">
    </ion-avatar>
"): FriendsListing@6:26
Parser Error: Unexpected token -, expected identifier, keyword, or string at column 32 in [let f of dataArray | alplabetic-ordering:f;] in FriendsListing@5:12 ("y | alplabetic-ordering:f;">
    <ion-avatar item-left (click)="viewFriendsProfile()">
        <img [ERROR ->][src]="f.imgURL">
    </ion-avatar>

0 个答案:

没有答案