Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/unix/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angular 水管坏了_Angular_Angular Pipe - Fatal编程技术网

Angular 水管坏了

Angular 水管坏了,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

我的管道文件如下所示:

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>

{{dealOpt}}
{{dealOPtion['option_name']| json}


我想应该是这样

  <li *ngFor="let dealOPtion of
(deal['products'][dealindex]['options']  |
unique) ;let dealOpt = index">

我收到错误未捕获错误:模板解析错误:无法找到管道“unique”(“所有产品['bundle_items'];let dealindex=index”>):@lintojohny那么你可能还没有在模块中声明管道。可能是读取?@lintojohny-在模块级别声明它是的,错误已经消失了。但是我添加管道是为了消除循环中的重复元素。它不是working@lintojohny-我不知道您的输入数据,即管道输入或收集结构,您必须共享代码如果这样做可以进一步帮助,我建议试着调试和检查结构和代码,根据它在这里共享的coe:@StackBlitz等平台上的PranayRana示例应该只支持问题-a应该在问题本身中。@jonrsharpe-如果你读到对我答案的评论,他的原始问题已经解决,现在他有了一个问题管道不工作的另一个问题是,以前他有编译器错误,这已经由我解决了answer@PranayRana然后,他们应该编辑这个问题,或者打开一个新的问题。
@NgModule({
  imports: [
  ],
  declarations: [UniquePipe ],
  providers: [],
  exports: [UniquePipe ]//this is needed if you want to export pipe
})
export class PipesModule { }