import { Component , OnInit } from '@angular/core' ; import { RestService } from '../rest.service' ; import { ActivatedRoute , Router } from '@angular/router' ; @ Component ( { selector : 'app-product' , templateUrl : './product.component.html' , styleUrls : [ './product.component.css' ] } ) export class ProductComponent implements OnInit { products : any = [ ] ; constructor ( public rest , private route , private router ) { } ngOnInit ( ) { this . getProducts ( ) ; } getProducts ( ) { this . products = [ ] ; this . rest . getProducts ( ) . subscribe ( ( data ) => { console . log ( data ) ; this . products = data ; } ) ; } add ( ) { this . router . navigate ( [ '/product-add' ] ) ; } delete ( id ) { this . rest . deleteProduct ( id ) . subscribe ( res => { this . getProducts ( ) ; } , ( err ) => { console . log ( err ) ; } ) ; } }