I have integrated a child component in my Angular application which contains two Boolean fields. I aim to respond promptly in the parent component whenever these values change.
///////////////////////////////////////////////////////
// Child Component
///////////////////////////////////////////////////////
@Component({
selector: 'critical',
template: `<div class="blueBorder"><h1>This is a critical component</h1></div>`,
styles: [`h1 { font-family: Lato; } .blueBorder {border: 1px solid blue;}`],
})
export class CriticalComponent {
error: boolean = false;
warning: boolean = false;
}
///////////////////////////////////////////////////////
// Parent Component
///////////////////////////////////////////////////////
@Component({
selector: 'my-app',
template: '<critical #criticalCmp></critical>',
styleUrls: ['./app.component.css'],
})
export class AppComponent {
@ViewChild('criticalCmp') criticalCmp: CriticalComponent;
onErrorsOrWarningsInCriticalComponent(): void {
// Execute this method each time the values in the critical-component are updated
// Perform API calls, log information, or other actions here
}
}
How can I achieve this functionality?
To demonstrate, you can view a StackBlitz example here: https://stackblitz.com/edit/angular-ivy-hpn8qy?file=src/app/app.component.ts