I'm attempt filtering data and rendering it in htmltable. Below my code: In module.ts
import Register10Pipe = require("./register10/register10.pipe");
@NgModule({
declarations: [
Register10Pipe.FilterPipe
])
In my.pipe.ts
import { Component, OnInit, Pipe, PipeTransform, Injectable } from '@angular/core';
@Pipe({
name: 'sectionGroup'
})
export class FilterPipe implements PipeTransform {
transform(items: any[], field: number, value: number): any[] {
if (!items) return [];
return items.filter(it => (+it[field]) === (+value));
}
}
In my.component.ts
import { FilterPipe } from './register10.pipe';
export class MyComponent implements OnInit {
filter: FilterPipe;
......
HTML where data must rendering
<ng-container *ngFor='let data1 of sectionList'>
<tr>
<td colspan="7">
{{data1.name}}
<button (click)="ArrRow($event)" style="float: right" id="{{data1.id}}">+</button>
</td>
</tr>
<tr *ngFor="let data2 of (model.Register10Data | filter:'sectionGroup':data1.id); let dataIndex = index">
<td>
{{dataIndex}}
</td>
</tr>
</ng-container>
sectionList it is Array of objects like myObj{number:id, string:name} I'm getting id from this array and trying to filter data that received from server. As i understand for this in angular can be using @Pipe. I know that there are other approaches, but this one I liked more. But I getting exception.
Unhandled Promise rejection: Template parse errors: The pipe 'filter' could not be found (" ]*ngFor="let data2 of (model.Register10Data | filter:'sectionGroup':data1.id); let dataIndex = index">"): e@68:20 ; Zone: ; Task: Promise.then ; Value: Error: Template parse errors: The pipe 'filter' could not be found (" ]*ngFor="let data2 of (model.Register10Data | filter:'sectionGroup':data1.id); let dataIndex = index">"): e@68:20
+doing in the pipe? - Christopher Mooredatain both of your nested for loops, that probably isn't helping - Christopher Moore