angular-cn/modules/angular2/docs/cheatsheet/lifecycle hooks.md

67 lines
1.8 KiB
Markdown
Raw Normal View History

2015-11-06 07:26:24 -05:00
@cheatsheetSection
Directive and component change detection and lifecycle hooks
@cheatsheetIndex 8
2015-11-06 07:26:24 -05:00
@description
(implemented as class methods)
@cheatsheetItem
syntax:
2015-11-06 07:26:24 -05:00
`constructor(myService: MyService, ...) { ... }`|`constructor(myService: MyService, ...)`
description:
2015-11-06 07:26:24 -05:00
The class constructor is called before any other lifecycle hook. Use it to inject dependencies, but avoid any serious work here.
@cheatsheetItem
syntax:
`ngOnChanges(changeRecord) { ... }`|`ngOnChanges(changeRecord)`
description:
2015-11-06 07:26:24 -05:00
Called after every change to input properties and before processing content or child views.
@cheatsheetItem
syntax:
`ngOnInit() { ... }`|`ngOnInit()`
description:
Called after the constructor, initializing input properties, and the first call to ngOnChanges.
2015-11-06 07:26:24 -05:00
@cheatsheetItem
syntax:
`ngDoCheck() { ... }`|`ngDoCheck()`
description:
2015-11-06 07:26:24 -05:00
Called every time that the input properties of a component or a directive are checked. Use it to extend change detection by performing a custom check.
@cheatsheetItem
syntax:
`ngAfterContentInit() { ... }`|`ngAfterContentInit()`
description:
Called after ngOnInit when the component's or directive's content has been initialized.
2015-11-06 07:26:24 -05:00
@cheatsheetItem
syntax:
`ngAfterContentChecked() { ... }`|`ngAfterContentChecked()`
description:
2015-11-06 07:26:24 -05:00
Called after every check of the component's or directive's content.
@cheatsheetItem
syntax:
`ngAfterViewInit() { ... }`|`ngAfterViewInit()`
description:
Called after ngAfterContentInit when the component's view has been initialized. Applies to components only.
2015-11-06 07:26:24 -05:00
@cheatsheetItem
syntax:
`ngAfterViewChecked() { ... }`|`ngAfterViewChecked()`
description:
2015-11-06 07:26:24 -05:00
Called after every check of the component's view. Applies to components only.
@cheatsheetItem
syntax:
`ngOnDestroy() { ... }`|`ngOnDestroy()`
description:
2015-11-06 07:26:24 -05:00
Called once, before the instance is destroyed.