OnChanges
interface
A lifecycle hook that is called when any data-bound property of a directive changes. Define an ngOnChanges()
method to handle the changes.
interface OnChanges {
ngOnChanges(changes: SimpleChanges): void
}
Class implementations
NgTemplateOutlet
NgComponentOutlet
NgModel
FormControlDirective
FormControlName
FormGroupDirective
MaxLengthValidator
MinLengthValidator
PatternValidator
RouterLinkWithHref
RouterLinkActive
UpgradeComponent
See also
DoCheck
OnInit
- Lifecycle Hooks guide
Methods
ngOnChanges() | |||
---|---|---|---|
A callback method that is invoked immediately after the default change detector has checked data-bound properties if at least one has changed, and before the view and content children are checked. | |||
ngOnChanges(changes: SimpleChanges): voidParameters
Returns
|
Usage notes
The following snippet shows how a component can implement this interface to define an on-changes handler for an input property.
@Component({selector: 'my-cmp', template: `...`})
class MyComponent implements OnChanges {
// TODO(issue/24571): remove '!'.
@Input() prop!: number;
ngOnChanges(changes: SimpleChanges) {
// changes.prop contains the old and the new value...
}
}
© 2010–2020 Google, Inc.
Licensed under the Creative Commons Attribution License 4.0.
https://v9.angular.io/api/core/OnChanges