ngOnChanges()

This is the documentation for Angular 6.
You can switch to the latest version Angular 7.

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): void

Example

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 {
  @Input() prop: number;

  ngOnChanges(changes: SimpleChanges) {
    // changes.prop contains the old and the new value...
  }
}