Search code examples
angularangular-pipe

Pipe is not working


My pipe file is looking like this:

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;

       }

}

component ts

import { UniquePipe } from './../../../services/unique.pipe';

component html

   <li *ngFor="let dealOPtion of
deal['products'][dealindex]['options'];let dealOpt = index |
unique">
                        {{ dealOpt }}
                        {{dealOPtion['option_name'] |json}}
     </li>

Solution

  • i think it should be like this

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

    put piple after collection


    as per comment you forgot to declare you pipe at module level so do as below

    @NgModule({
      imports: [
      ],
      declarations: [UniquePipe ],
      providers: [],
      exports: [UniquePipe ]//this is needed if you want to export pipe
    })
    export class PipesModule { }