Component Classes
- Components are just ES6 classes
- Properties and methods of the component class are available to the template
- Providers (Services) are injected in the constructor
- The component lifecycle is exposed with hooks
export class ItemsComponent implements OnInit {
items: Item[];
selectedItem: Item;
constructor(
private itemsService: ItemsService
) {}
ngOnInit() {
this.getItems();
}
getItems() {
this.itemsService.loadItems()
.subscribe((items: Item[]) => this.items = items);
}
}
Backlinks