Advertisement
Guest User

Untitled

a guest
Jun 25th, 2019
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.12 KB | None | 0 0
  1. import { Component, OnInit } from '@angular/core';
  2. import { CategoryService } from 'src/app/category.service';
  3. import { ProductService } from 'src/app/product.service';
  4. import { Router, ActivatedRoute } from '@angular/router';
  5. import 'rxjs/add/operator/take';
  6.  
  7. @Component({
  8. selector: 'app-product-form',
  9. templateUrl: './product-form.component.html',
  10. styleUrls: ['./product-form.component.css']
  11. })
  12. export class ProductFormComponent implements OnInit {
  13. categories$;
  14. product = {};
  15. //productService: any;
  16.  
  17. constructor(
  18. private router: Router,
  19. private route: ActivatedRoute,
  20. //private categoryService: CategoryService,
  21. private productService: ProductService) {
  22. //this.categories$ = categoryService.getCategories()
  23.  
  24.  
  25. let id = this.route.snapshot.paramMap.get('id');
  26. if (id) this.productService.get(id).take(1).subscribe(p => this.product = p);
  27. //if (id) this.productService.get(id).valueChanges().subscribe(p => this.product = p);
  28. }
  29.  
  30. save(product){
  31. this.productService.create(product);
  32. this.router.navigate(['admin/products']);
  33. //console.log(product);
  34. }
  35. ngOnInit() {
  36. }
  37.  
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement