Advertisement
Shell_Casing

delete page

Nov 10th, 2018
330
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import { Component, OnInit } from '@angular/core';
  2. import { ProductService } from '../../product.service';
  3. import { Router } from '@angular/router';
  4. import { ProductInterface } from '../../product-interface';
  5.  
  6. @Component({
  7.   selector: 'app-admin-products',
  8.   templateUrl: './admin-products.component.html',
  9.   styleUrls: ['./admin-products.component.css']
  10. })
  11. export class AdminProductsComponent implements OnInit {
  12.   products: ProductInterface[] = [];
  13.  
  14.   constructor(private productService: ProductService, private router: Router) { }
  15.  
  16.   ngOnInit() {
  17.     this.getProducts();
  18.   }
  19.  
  20.   editProduct(id) {
  21.     this.router.navigate([`/admin/products/${id}`]);
  22.   }
  23.  
  24.   deleteProduct(id) {
  25.     if (confirm('You are about to permanently remove this product. Continue?')) {
  26.       this.productService.deleteAProduct(id).subscribe(() => this.ngOnInit());
  27.     }
  28.   }
  29.  
  30.   getProducts() {
  31.     this.productService.getAllProducts().subscribe((products: ProductInterface[]) => {
  32.       console.log(products);
  33.       this.products = products;
  34.     });
  35.   }
  36.  
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement