daily pastebin goal
33%
SHARE
TWEET

Untitled

a guest Feb 14th, 2018 72 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import { Component, OnInit } from '@angular/core';
  2. import { Router } from '@angular/router';
  3. import { Title } from '@angular/platform-browser';
  4.  
  5. import { Product, Category } from '../../models/product.model';
  6. import { ProductsService } from '../../services/products.service';
  7.  
  8. @Component({
  9.     selector: 'products',
  10.     templateUrl: 'products.component.html'
  11. })
  12.  
  13. export class ProductsComponent implements OnInit {
  14.     categories: Category[];
  15.     products: Product[];
  16.  
  17.     tableMessages: Object = {
  18.         totalMessage: 'items'
  19.     };
  20.  
  21.     defaultSort: Object[] = [
  22.         { prop: 'id', dir: 'description' }
  23.     ];
  24.  
  25.     constructor(
  26.         private title: Title,
  27.         private router: Router,
  28.         private productsService: ProductsService
  29.     ) {}
  30.  
  31.     ngOnInit(): void {
  32.         this.title.setTitle('Products');
  33.  
  34.         this.productsService.getProductCategories()
  35.             .subscribe(categories => this.categories = categories);
  36.  
  37.         this.productsService.getProducts()
  38.             .subscribe(products => this.products = products);
  39.     }
  40.  
  41.     getCategoryName(id: number): string | null {
  42.         let category = this.categories.find(category => category.id === id);
  43.  
  44.         return category ? category.name : null;
  45.     }
  46.  
  47.     onActivate(event: any): void {
  48.         this.router.navigate(['/product', event.row.id]);
  49.     }
  50. }
RAW Paste Data
Top