Complete the code to import the lifecycle hook interface for detecting input changes.
import { Component, Input, [1] } from '@angular/core';
The OnChanges interface is used to detect changes to input properties in Angular components.
Complete the component class declaration to implement the interface for input change detection.
export class MyComponent implements [1] {
Implementing OnChanges allows the component to respond when input properties change.
Fix the error in the method signature to correctly detect input changes.
ngOnChanges([1]: SimpleChanges) { console.log('Input changed'); }
The parameter name is conventionally changes and it holds the changes to input properties.
Fill both blanks to declare an input property and detect its changes.
@Input() [1]: string; ngOnChanges(changes: [2]) { if (changes.[1]) { console.log('Value changed:', changes.[1].currentValue); } }
The input property is named 'title'. The ngOnChanges method receives a SimpleChanges object to track changes.
Fill all three blanks to create a component that logs changes to an input property named 'count'.
import { Component, Input, [1], SimpleChanges } from '@angular/core'; @Component({ selector: 'app-counter', template: '<p>{{count}}</p>' }) export class CounterComponent implements [2] { @Input() [3]: number = 0; ngOnChanges(changes: SimpleChanges) { if (changes.count) { console.log('Count changed to', changes.count.currentValue); } } }
The component imports and implements OnChanges. The input property is named 'count' to track changes.