File

modules/categories-component/src/categories.component.ts

Description

Categories component. Display list of store categories

Metadata

selector app-categories
styleUrls categories.component.scss
templateUrl categories.component.html

Inputs

generalCategoryId

Id of general category

Type: string | number

routeName

Name of specific category route

Type: string

Constructor

constructor(productService: any, router: any)

Methods

getCategories
getCategories()

Get categories and patch to variable

Returns: void
onSelect
onSelect(categoryId: any)

On select category navigate to specific category

Parameters :
  • categoryId

    category id

Returns: void

Properties

Public categories
categories: any[]

Store categories

import { Router } from '@angular/router';
import { ProductService } from '@nodeart/productservice';
import { Component, OnInit, Input } from '@angular/core';

/**
 * Categories component. Display list of store categories
 */
@Component({
  selector: 'app-categories',
  templateUrl: './categories.component.html',
  styleUrls: ['./categories.component.scss']
})
export class CategoriesComponent implements OnInit {

  /**
   * Store categories
   */
  public categories = [];

  /**
   * Id of general category
   */
  @Input() public generalCategoryId: string | number;
  
  /**
   * Name of specific category route
   */
  @Input() public routeName: string;

  constructor(protected productService: ProductService,
              protected router: Router) { }

  ngOnInit() {
    this.getCategories();
  }

  /**
   * Get categories and patch to variable
   */
  getCategories(): void {
    this.productService.getCategories(this.generalCategoryId).subscribe( categories => {
      if(categories.val()){
        this.categories = categories.val().map(category => {
          category['_source']['id'] = category['_id'];
          return category['_source'];
        });
      }
    });
  }

  /**
   * On select category navigate to specific category
   * @param categoryId category id
   */
  onSelect(categoryId){
    this.router.navigate([this.routeName, categoryId]);
  }

}

results matching ""

    No results matching ""