import { Component } from "@angular/core";
@Component({
selector: 'pm-root',
template: `
<div>
<h1>{{pageTitle}}</h1>
<pm-products></pm-products>
</div>`
})
export class AppComponent {
pageTitle: string = 'Acme Product Management';
}
<pm-products>
*ngIf
: If logic *ngFor: For loops
<img [src]='product.imageUrl'
[title]='product.productName'
[style.width.px]='imageWidth'
[style.margin.px]='imageMargin' />
imageWidth: number = 50;
imageMargin: number = 2;
<button class='btn btn-primary'
(click)='toggleImage()'>
Show Image
</button>
{{product.productCode | lowercase}}
{{product.releaseDate}}
{{product.price | currency:'USD':'symbol':'1.2-2'}}
Custom pipes
**TODO Add Building Custom Pipes notes
export interface IProduct {
productId: number;
productName: string;
productCode: string;
releaseDate: string;
price: number;
description: string;
starRating: number;
imageUrl: string;
calculateDiscount(percent: number): number;
}
The best place to set default values for more complex properties is in the class constructor.
The class constructor is a function that is executed when the component is first initialized.