-1

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>
Pranay Rana
  • 175,020
  • 35
  • 237
  • 263
linto johny
  • 137
  • 1
  • 2
  • 9
  • share you coe here : https://stackblitz.com/ – Pranay Rana Mar 29 '18 at 12:45
  • @PranayRana examples on platforms like StackBlitz should only be *supporting* the question - a [mcve] should be in the question itself. – jonrsharpe Mar 29 '18 at 16:19
  • @jonrsharpe - if you read comment on my answer , his orginal issue is resolved and now he is having another issue that pipe is not working , previously he is having compiler error which already resolved by my answer – Pranay Rana Mar 29 '18 at 18:11
  • 1
    @PranayRana then they should either edit this question or open a new one **with a [mcve] in**. – jonrsharpe Mar 29 '18 at 19:33

1 Answers1

0

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 { }
Pranay Rana
  • 175,020
  • 35
  • 237
  • 263
  • i am getting error Uncaught Error: Template parse errors: The pipe 'unique' could not be found ("al of products['bundled_items'];let dealindex = index">
  • ]ion of (deal['products'][dealindex]['options'] | unique) ;let dealOpt = index">"):
  • – linto johny Mar 29 '18 at 10:09
  • @lintojohny then presumably you *haven't* actually declared the pipe in the module. Maybe read [the pipe docs](https://angular.io/guide/pipes#custom-pipes)? – jonrsharpe Mar 29 '18 at 10:12
  • @lintojohny - declare it at module level – Pranay Rana Mar 29 '18 at 10:12
  • yeah, the error is gone. but I added the pipe to eliminate repeating elements from the loop. it's not working – linto johny Mar 29 '18 at 10:22
  • @lintojohny - i dont know your input data i.e. pipe input or collection strucute you have to share code some where so can help further, i suggest try to debug and check structure and code according to it – Pranay Rana Mar 29 '18 at 10:28
  • 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; } }after search i got this pipe code to eliminate repeated items from the array – linto johny Mar 29 '18 at 10:33
  • @lintojohny - it diffcult please share code on stackbiz.com – Pranay Rana Mar 29 '18 at 10:39