Advertisement
tellitabie

Component

Mar 5th, 2021
1,055
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import { Component, OnInit } from '@angular/core';
  2. import { ActivatedRoute } from "@angular/router";
  3.  
  4. import { ProductService } from "../services/product.service";
  5. import { CartService } from "../services/cart.service";
  6.  
  7. @Component({
  8.   selector: 'app-product',
  9.   templateUrl: './product.component.html',
  10.   styleUrls: ['./product.component.css']
  11. })
  12. export class ProductComponent implements OnInit {
  13.   products: any;
  14.  
  15.   constructor(private productService: ProductService, private route: ActivatedRoute, private cartService: CartService) {
  16.  
  17.   }
  18.  
  19.   ngOnInit(): void {
  20.     this.getProductById();
  21.   }
  22.  
  23.   // tslint:disable-next-line:typedef
  24.   getProductById() {
  25.     const id = this.route.snapshot.paramMap.get('id');
  26.     this.productService.getProduct(+id)
  27.       .subscribe(data => this.products = data);
  28.   }
  29.  
  30.   // tslint:disable-next-line:typedef
  31.   addToCart(data){
  32.     this.cartService.addItemToCart(data)
  33.       .subscribe();
  34.   }
  35.  
  36. }
  37.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement