You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

27 lines
701 B
TypeScript

import { Component, OnInit } from '@angular/core';
import { HttpService } from '../../services/http.service'
import { Product } from '../../models/product'
@Component({
selector: 'app-product-list',
templateUrl: './product-list.component.html',
styleUrls: ['./product-list.component.scss']
})
export class ProductListComponent implements OnInit {
products: Product[] = []
constructor(private httpService: HttpService) { }
ngOnInit(): void {
this.httpService.getProducts().subscribe( (res: Product[]) => {
this.products = res
})
}
markAsFavorite(product: any): void {
console.log(`${product.name} has been added to favorites.`);
product.favorite = true
}
}