- Hands-On Full Stack Web Development with Angular 6 and Laravel 5
- Fernando Monteiro
- 249字
- 2021-07-23 19:18:52
The component life cycle
In the life cycle of an Angular component, after instantiating, the component runs a definite path of execution from its beginning until its end. The most basic way to understand this is through observing the following code:
export class HelloComponent implements OnInit, OnDestroy {
constructor() { }
ngOnInit() {
... Some code goes here
}
ngOnDestroy() {
... Some code goes here
}
}
In the preceding example, you can see methods called ngOnInit() and ngOnDestroy; the names are very intuitive, and show us that we have a beginning and an end. The ngOnInit() method is implemented through its OnInit interface, and the same goes for the ngOnDestroy() method. As you saw in the previous chapter, the interfaces in TypeScript are very useful – it's not any different here.
In the following diagram, we will look at the main interfaces that we can implement on a component. In the diagram, after the Constructor() method, there are eight interfaces (also known as hooks); each one is responsible for one thing, at a specific moment:

We will not describe the interfaces one by one in this chapter, so as not to overload you, but, throughout the course of the book, we will use them in the application that we will build. Also, the preceding link includes detailed information about each interface and hook.
- EJB 3.1從入門到精通
- 智能網(wǎng)聯(lián)汽車V2X與智能網(wǎng)聯(lián)設(shè)施I2X
- 物聯(lián)網(wǎng)識別技術(shù)
- 互聯(lián)網(wǎng)安全的40個智慧洞見:2014年中國互聯(lián)網(wǎng)安全大會文集
- 智慧光網(wǎng)絡(luò):關(guān)鍵技術(shù)、應(yīng)用實踐和未來演進
- 網(wǎng)絡(luò)環(huán)境中基于用戶視角的信息質(zhì)量評價研究
- 新手易學(xué):新手學(xué)淘寶開店
- Working with Legacy Systems
- Android UI Design
- 端到端QoS網(wǎng)絡(luò)設(shè)計
- Learning Storm
- 深入理解Nginx:模塊開發(fā)與架構(gòu)解析
- 信息技術(shù)安全評估準(zhǔn)則:源流、方法與實踐
- Migrating to Drupal7
- 無線傳感器網(wǎng)絡(luò)定位方法及應(yīng)用