-
Notifications
You must be signed in to change notification settings - Fork 36
Expand file tree
/
Copy pathproduct-edit.component.ts
More file actions
31 lines (25 loc) · 955 Bytes
/
product-edit.component.ts
File metadata and controls
31 lines (25 loc) · 955 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
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: RestService, private route: ActivatedRoute, private router: 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);
});
}
}