concept productitemcomponent in category angular

appears as: ProductItemComponent, ProductItemComponent, The ProductItemComponent
Angular Development with Typescript, Second Edition

This is an excerpt from Manning's book Angular Development with Typescript, Second Edition.

Figure 3.13. Six instances of ProductItemComponent

Figure 3.13 shows six products, each an instance of ProductItemComponent.

Figure 3.13. Six instances of ProductItemComponent

ProductItemComponent knows how to render one product based on the product provided by its parent (HomeComponent). Modify product-item.component.ts to look like the following listing.

Listing 3.24. product-item.component.ts
import {Component, Input} from '@angular/core';
import {Product} from '../shared/product.service';

@Component({
  selector: 'nga-product-item',
  templateUrl: './product-item.component.html',
  styleUrls: ['./product-item.component.css']
})
export class ProductItemComponent {

  @Input() product: Product;          #1
 }

The product to render will be given to ProductItemComponent via its property product decorated with @Input(). The @Input() properties are described in section 8.2.1. in chapter 8.

Your HomeComponent hosts several instances of ProductItemComponent. Now let’s add more styles to home.component.css so the products are displayed nicely and aligned using the CSS style flex. Add the following listing’s styles to home.component.css.