modules/general-categories-all/src/general-category-all.component.ts
Displays display all products from general category or products from child category. Has pagination
selector | app-general-category-all |
styleUrls | general-category-all.component.scss |
templateUrl | general-category-all.component.html |
categoryIds
|
Store category ids |
from
|
From what index of product start. Default 0
Default value: |
size
|
How many products display. Default 10
Default value: |
constructor(productService: any, zone: any, router: any)
|
getProducts |
getProducts(categoryIds: any)
|
Get product from specific categories
Parameters :
Returns:
void
|
categoryFilter |
categoryFilter(categoryId: any)
|
Get products from specific category
Parameters :
Returns:
void
|
onSelect |
onSelect(id: any)
|
On select a product redirect to product page
Parameters :
Returns:
void
|
products |
products: |
Array of products. |
import { ActivatedRoute, Params } from '@angular/router';
import { Router } from '@angular/router';
import { ProductService } from '@nodeart/productservice';
import { Component, OnInit, Input, NgZone, OnChanges } from '@angular/core';
import {LoadingPage} from '@nodeart/loading-indicator';
/**
* Displays display all products from general category or products from child category. Has pagination
*
*/
@Component({
selector: 'app-general-category-all',
templateUrl: './general-category-all.component.html',
styleUrls: ['./general-category-all.component.scss']
})
export class GeneralCategoryAllComponent extends LoadingPage implements OnInit, OnChanges {
/**
* Store category ids
*/
@Input() categoryIds;
/**
* From what index of product start. Default 0
*/
@Input() from = 0;
/**
* How many products display. Default 10
*/
@Input() size = 10;
/**
* Array of products.
*/
products = [];
constructor(protected productService: ProductService, protected zone: NgZone, protected router: Router) {
super(true);
}
ngOnInit() {
console.log(this.categoryIds);
this.getProducts(this.categoryIds);
}
ngOnChanges(changes) {
this.getProducts(this.categoryIds);
}
/**
* Get product from specific categories
* @param categoryIds Array of category ids
*/
getProducts(categoryIds){
this.standby();
this.products = [];
console.log( categoryIds );
console.log( "Size: " + this.size + ", From: " + this.from );
this.productService.getProductsByCategoryIds(categoryIds, this.size, this.from).subscribe( data => {
if(data.val()){
let products = data.val().map(item => {
item['_source']['id'] = item['_id'];
return item['_source'];
});
console.log(products);
this.zone.run(() => {
this.products = products;
this.ready();
});
}
});
}
/**
* Get products from specific category
* @param categoryId category id
*/
categoryFilter(categoryId){
this.categoryIds = categoryId;
this.getProducts(this.categoryIds);
}
/**
* On select a product redirect to product page
* @param id id of product
*/
onSelect(id) {
this.router.navigate(['product', id]);
}
}