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 , protected zone , protected router ) { super ( true ) ; } ngOnInit ( ) { console . log ( this . categoryIds ) ; this . getProducts ( this . categoryIds ) ; } ngOnChanges ( changes ) { this . getProducts ( this . categoryIds ) ; } param categoryIds 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 ( ) ; } ) ; } } ) ; } param categoryId categoryFilter ( categoryId ) { this . categoryIds = categoryId ; this . getProducts ( this . categoryIds ) ; } param id onSelect ( id ) { this . router . navigate ( [ 'product' , id ] ) ; } }