0

I have created one pipe to sort an object array based on the value of the object property.keep all Objects with property show==0 and show==1 are removed,there is no any error and can be seen in the console.

pipe.ts

@Pipe({
    name: 'menufilter'
})
@Injectable()
export class MyMenuFilterPipe implements PipeTransform {
    transform(items: any[], args: any[]): any {
        if (items) {
            return items.filter(item => item.show == '0',console.log(item));
        }
    }

app.html

<tr  *ngFor="let menu of specificmenus|menufilter" >
     <td >{{menu.name}}</td>
</tr>
CozyAzure
  • 8,280
  • 7
  • 34
  • 52
Ajith
  • 775
  • 1
  • 13
  • 47
  • Are you sure the `.show` property is a type of string, and not a number? There is a big difference between `'0'` and `0` – CozyAzure Jul 27 '17 at 08:33
  • @CozyAzure Its 32 bit intiger ,im getting the same result in the console while using '0' and 0 – Ajith Jul 27 '17 at 08:39
  • Could you reproduce the issue in a plunker? Based on what I'm seeing (and tried your code) it should work just fine :) – AT82 Jul 27 '17 at 09:19

2 Answers2

0

Because you are not returning anything

transform(items: any[], args: any[]): any {
    if (items){
      return items.filter(item =>{
        console.log(items)
        return item.show=='0';
      })
      }
    }
Aravind
  • 40,391
  • 16
  • 91
  • 110
  • 1
    if you look at his syntax properly; he did return the value. Fat arrow notations doenst require the `return` keyword if you dont have the curly braces. Though, there will be no effect of him passing in the console.log as a second argument in the callback – CozyAzure Jul 27 '17 at 08:26
0

Remove ",console.log(item)" And retry!

jackjoy
  • 101
  • 1
  • 2