1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
|
import {
Component,
EventEmitter,
Input,
Output
} from '@angular/core';
import { Product } from '../product.model';
@Component({
selector: 'products-list',
templateUrl: './products-list.component.html'
})
export class ProductsListComponent {
/**
* @input productList - the Product[] passed to us
*/
@Input() productList: Product[];
/**
* @output onProductSelected - outputs the current
*
Product whenever a new Product is selected
*/
@Output() onProductSelected: EventEmitter<Product>;
/**
* @property currentProduct - local state containing
*
the currently selected `Product`
*/
private currentProduct: Product;
constructor() {
this.onProductSelected = new EventEmitter();
}
clicked(product: Product): void {
this.currentProduct = product;
this.onProductSelected.emit(product);
}
isSelected(product: Product): boolean {
if (!product || !this.currentProduct) {
return false;
}
return product.sku === this.currentProduct.sku;
}
} |
Partager