我正在使用ionic 2並嘗試在*ngFor=""
中對我的數組進行排序。Angular 2管道參數失敗
可悲的是它引發了我的錯誤,我不知道爲什麼,這裏是related post
我管看起來是這樣的:
import {Injectable, Pipe} from '@angular/core';
import * as _ from 'lodash';
@Pipe({ name: 'order-by' })
export class OrderByPipe {
transform(array, args) {
return _.sortBy(array, args);
}
}
我* ngFor:
<button ion-item *ngFor="let user of users | order-by:'likes'" >
錯誤或
TypeError: Cannot read property 'toUpperCase' of undefined ("
<ion-list>
<button ion-item [ERROR ->]*ngFor="let user of users | order-by: 'likes'">
其他的也一樣problem。不知道爲什麼它不起作用..
做有可能有另一個管道排序數組? :) 謝謝 !
任何錯誤在瀏覽器控制檯? –
可能是管道名稱?我有一個名爲'orderBy'的類似管道可以工作。另外,我將'args'作爲'Array'傳入:'['likes']'。 – Arg0n
@GünterZöchbauer錯誤的控制檯是在我的問題下的錯誤標題(更新) @ Arg0n沒有管道名稱在裝飾器'@Pipe({name:'order-by'})'所以我認爲是正確的。你的管道是按孩子值排序的嗎? :) – luiswill