Angular 水管坏了
我的管道文件如下所示: pipe.tsAngular 水管坏了,angular,angular-pipe,Angular,Angular Pipe,我的管道文件如下所示: 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 eleme
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>
{{dealOpt}}
{{dealOPtion['option_name']| json}
我想应该是这样
<li *ngFor="let dealOPtion of
(deal['products'][dealindex]['options'] |
unique) ;let dealOpt = index">
我收到错误未捕获错误:模板解析错误:无法找到管道“unique”(“所有产品['bundle_items'];let dealindex=index”>
@NgModule({
imports: [
],
declarations: [UniquePipe ],
providers: [],
exports: [UniquePipe ]//this is needed if you want to export pipe
})
export class PipesModule { }