0
0
Angularframework~5 mins

@Output decorator with EventEmitter in Angular - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is the purpose of the @Output decorator in Angular?
The @Output decorator allows a child component to send data or events to its parent component. It marks a property as an event that the parent can listen to.
Click to reveal answer
beginner
What role does EventEmitter play when used with @Output?
EventEmitter is a class that creates an event stream. When used with @Output, it lets the child component emit events that the parent component can subscribe to and react.
Click to reveal answer
beginner
How do you emit an event from a child component using EventEmitter?
You call the emit() method on the EventEmitter instance, passing the data you want to send to the parent. For example: this.myEvent.emit(data);
Click to reveal answer
beginner
In the parent component template, how do you listen to an event emitted by a child component's @Output property?
You use event binding syntax with parentheses around the event name, like . The $event holds the emitted data.
Click to reveal answer
intermediate
Why is using @Output with EventEmitter better than directly accessing child component properties?
It keeps components loosely coupled and follows Angular's unidirectional data flow. The child only emits events, and the parent decides how to handle them, improving maintainability.
Click to reveal answer
What does the @Output decorator do in Angular?
AAllows a child component to send events to its parent
BImports external modules
CDefines a service
DCreates a new component
Which class is used with @Output to emit events?
APromise
BObservable
CEventEmitter
DSubject
How do you emit an event named 'update' with data '42' from a child component?
Athis.update.emit(42);
Bemit.update(42);
Cthis.emit(update, 42);
Dupdate.emitEvent(42);
In the parent template, how do you listen to a child's @Output event named 'change'?
A<child {change}="onChange($event)"></child>
B<child [change]="onChange($event)"></child>
C<child #change="onChange($event)"></child>
D<child (change)="onChange($event)"></child>
Why should components use @Output and EventEmitter instead of directly accessing child properties?
ATo make components dependent on each other
BTo keep components loosely coupled and maintain unidirectional data flow
CTo increase code complexity
DTo avoid using Angular features
Explain how a child component can send data to its parent using @Output and EventEmitter in Angular.
Think about how events flow from child to parent.
You got /4 concepts.
    Describe why using @Output with EventEmitter is important for component communication in Angular.
    Consider the benefits of clear communication paths.
    You got /4 concepts.