import { Component , OnInit , Input } from '@angular/core' ; import { RestService } from '../rest.service' ; import { ActivatedRoute , Router } from '@angular/router' ; @ Component ( { selector : 'app-product-edit' , templateUrl : './product-edit.component.html' , styleUrls : [ './product-edit.component.css' ] } ) export class ProductEditComponent implements OnInit { @ Input ( ) productData : any = { prod_name : '' , prod_desc : '' , prod_price : 0 } ; constructor ( public rest , private route , private router ) { } ngOnInit ( ) { this . rest . getProduct ( this . route . snapshot . params [ 'id' ] ) . subscribe ( ( data ) => { console . log ( data ) ; this . productData = data ; } ) ; } updateProduct ( ) { this . rest . updateProduct ( this . route . snapshot . params [ 'id' ] , this . productData ) . subscribe ( ( result ) => { this . router . navigate ( [ '/product-details/' + result . _id ] ) ; } , ( err ) => { console . log ( err ) ; } ) ; } }