I'm creating a https://github.com/MIt9/angular-4-data-table with my data from firebase. My problem is, i have route naviagation with 'name' parameter. I click on link and i want to display only this which equals to my passed 'name' parameter. I click on link and shows me all products from db in Array of objects. How to filter this? I need to do filter before pass it to my data-table.
component.ts file:
productCategory: Product[];
filteredProducts: any[];
subscription: Subscription;
tableResource: DataTableResource<Product>;
name;
items: Product[] = [];
itemCount: number;
constructor(
private productService: ProductsService,
private route: ActivatedRoute
) {
this.route.paramMap.subscribe(params => {
let name = params.get("name");
this.name = name;
this.subscription = this.productService.getAll().subscribe(products => {
this.filteredProducts = this.productCategory = products;
// here i think i want to filter input data and pass this into variable
let category = products.filter(products => products.category);
console.log(category);
this.InitializeTable(category);
});
});
}
private InitializeTable(products: Product[]) {
this.tableResource = new DataTableResource(products);
this.tableResource.query({ offset: 0 }).then(items => (this.items = items));
this.tableResource.count().then(count => (this.itemCount = count));
}
reloadItems(params) {
if (!this.tableResource) return;
this.tableResource.query(params).then(items => (this.items = items));
}
myArray.find( a => a.name === 'thing')-- does regular JS array filtering not work?