我的管道文件如下所示:
pipe.ts
import { Pipe, PipeTransform } from '@angular/core';
@Pipe({ name: 'unique', pure: false
}) export class UniquePipe implements PipeTransform {
transform(value: any, args?: any): any {
// Remove the duplicate elements
let uniqueArray = value.filter(function (el, index, array) {
return array.indexOf (el) == index;
});
return uniqueArray;
}
}
组件ts
import { UniquePipe } from './../../../services/unique.pipe';
组件html
<li *ngFor="let dealOPtion of
deal['products'][dealindex]['options'];let dealOpt = index |
unique">
{{ dealOpt }}
{{dealOPtion['option_name'] |json}}
</li>
答案 0 :(得分:0)
我认为应该是这样的
<li *ngFor="let dealOPtion of
(deal['products'][dealindex]['options'] |
unique) ;let dealOpt = index">
收集后放入piple
根据评论,您忘记在模块级别声明管道,因此请执行以下操作
@NgModule({
imports: [
],
declarations: [UniquePipe ],
providers: [],
exports: [UniquePipe ]//this is needed if you want to export pipe
})
export class PipesModule { }