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