Complete the code to pass data from a parent to a child component using Angular.
import { Component, [1] } from '@angular/core'; @Component({ selector: 'app-child', template: `<p>Message: {{ message }}</p>` }) export class ChildComponent { @[1]() message!: string; }
Use @Input() to receive data from a parent component.
Complete the code to emit an event from a child component to notify the parent.
import { Component, Output, EventEmitter, [1] } from '@angular/core'; @Component({ selector: 'app-child', template: `<button (click)="notifyParent()">Notify Parent</button>` }) export class ChildComponent { @Output() notify = new [1]<void>(); notifyParent() { this.notify.[2](); } }
EventEmitter is used to create an event, and emit() sends the event to the parent.
Fix the error in the parent component template to listen to the child's event.
<app-child ([1])="onNotify()"></app-child>
The event name matches the @Output() property name in the child component, which is notify.
Fill both blanks to create a two-way binding between parent and child components.
<app-child [( [1] )]="[2]"></app-child>
Two-way binding uses the property name inside [( )] and the parent component's variable to bind data.
Fill all three blanks to create a reactive signal in Angular and update it on button click.
import { Component, [1] } from '@angular/core'; @Component({ selector: 'app-counter', template: ` <p>Count: {{ count() }}</p> <button (click)="[2]()">Increment</button> ` }) export class CounterComponent { count = [3](0); increment() { this.count.set(this.count() + 1); } }
Angular signals are created with signal(). The method increment() updates the signal. The template calls count() to get the current value.