### File

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

### Metadata

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

### Constructor

`constructor(productService: any, router: any)`

### Methods

getCategories
`getCategories()`
Returns: `void`

onSelect
`onSelect(categoryId: any)`
Returns: `void`

### Properties

Public categories
`categories: `any[]` </bcode>`

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

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

      public categories = [];

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

      ngOnInit() {
        this.getCategories();
      }

      getCategories(): void {
        this.productService.getCategories().on('value', categories => {
          if(categories.val()){
            this.categories = categories.val().map(category => {
              category['_source']['id'] = category['_id'];
              return category['_source'];
            });
          }
        });
      }

      onSelect(categoryId){
        this.router.navigate(['category', categoryId]);
      }

    }

# results matching ""

# No results matching ""