import { Component, OnInit } from '@angular/core'; import { ProductService } from './../../services/product.service'; import { Product } from './../../models/product'; import { Router } from '@angular/router'; import { CartService } from 'src/app/services/cart.service'; @Component({ selector: 'app-home', templateUrl: './home.component.html', styleUrls: ['./home.component.css'], }) export class HomeComponent implements OnInit { public products: Product[]; public Searchedproducts: Product[]; searchValue: string = ''; constructor( private productservice: ProductService, private router: Router, private cartservice: CartService ) {} public showCart() { this.router.navigateByUrl('/showCart'); } addCart(item: any) { this.cartservice.addtoCart(item); } searchProduct() { if (this.searchValue == '') { this.Searchedproducts = this.products; } else { this.Searchedproducts = this.products.filter((p) => p.productname.toLocaleLowerCase().includes(this.searchValue) ); } } EditProfile() { this.router.navigateByUrl('/user-profile-details'); } Members() { this.router.navigateByUrl('/memberlist'); } ngOnInit(): void { this.productservice.showAllProduct().subscribe((res) => { this.products = res; this.Searchedproducts = res; }); } }