What is the main way a child component sends data to its parent in Angular?
The child component uses an @Output property with an EventEmitter to send data to the parent component.
Click to reveal answer
beginner
How do you declare an event in a child component to notify the parent?
You declare an @Output() eventName = new EventEmitter<type>(); in the child component class.
Click to reveal answer
beginner
How does the parent component listen to events from the child component?
In the parent template, bind to the child's event like <child (eventName)="parentHandler($event)"></child>.
Click to reveal answer
intermediate
Why is using @Output with EventEmitter better than directly accessing child properties?
It keeps components loosely coupled and follows Angular's unidirectional data flow, making the app easier to maintain.
Click to reveal answer
beginner
What is the role of the $event object in child to parent communication?
$event carries the data emitted by the child component's EventEmitter and is received by the parent's event handler.
Click to reveal answer
Which decorator is used in Angular to send data from a child to a parent component?
A@Output
B@Input
C@ViewChild
D@Injectable
✗ Incorrect
The @Output decorator is used with EventEmitter to send data from child to parent.
What Angular class is used to emit events from a child component?
AObservable
BEventEmitter
CSubject
DPromise
✗ Incorrect
EventEmitter is the class used to emit custom events in Angular components.
How does the parent component receive data from the child component's event?
ABy using @Input in the parent
BBy calling a method on the child component directly
CBy binding to the child's event in the template using (eventName)
DBy using a service only
✗ Incorrect
The parent listens to the child's event by binding to it in the template with (eventName).
What does the $event variable represent in Angular event binding?
AThe Angular lifecycle hook
BThe parent component instance
CThe child component's template
DThe data emitted by the child component's event
✗ Incorrect
$event holds the data sent from the child component's EventEmitter.
Which of these is NOT a recommended way to communicate from child to parent in Angular?
ADirectly modifying parent properties from child
BUsing event binding in the parent template
CUsing @Output with EventEmitter
DPassing data via emitted events
✗ Incorrect
Directly modifying parent properties from child breaks encapsulation and is not recommended.
Explain how a child component sends data to its parent in Angular. Include the decorators and classes involved.
Think about how events work in Angular templates.
You got /4 concepts.
Describe why using @Output and EventEmitter is a good practice for child to parent communication in Angular.
Consider component independence and data flow direction.
You got /4 concepts.
Practice
(1/5)
1. What is the main Angular feature used for communication from a child component to its parent?
easy
A. Using ViewChild to access parent methods
B. Using @Input to send data
C. Using services with HttpClient
D. Using @Output with EventEmitter
Solution
Step 1: Understand child to parent communication
Child components send data or events to parents using Angular's event system.
Step 2: Identify Angular feature for this
@Output decorator with EventEmitter allows child to emit events the parent listens to.
Final Answer:
Using @Output with EventEmitter -> Option D
Quick Check:
Child to parent = @Output + EventEmitter [OK]
Hint: Child emits events with @Output and EventEmitter [OK]
Common Mistakes:
Confusing @Input as child to parent communication
Thinking services are needed for simple child to parent
Using ViewChild to call parent methods directly
2. Which of the following is the correct syntax to declare an event emitter in a child component?
easy
A. notify = new EventEmitter<string>();
B. @Input() notify = new EventEmitter<string>();
C. @Output() notify = new EventEmitter<string>();
D. @Output notify = EventEmitter<string>();
Solution
Step 1: Recall correct decorator and initialization
Event emitters must be decorated with @Output() and initialized with new EventEmitter<type>().
Step 2: Check each option
@Output() notify = new EventEmitter<string>(); correctly uses @Output() and initializes the emitter. Others miss decorator, use wrong decorator, or wrong syntax.
Final Answer:
@Output() notify = new EventEmitter<string>(); -> Option C
Quick Check:
@Output() + new EventEmitter() = correct syntax [OK]
Hint: Always use @Output() with new EventEmitter() [OK]
Common Mistakes:
Using @Input instead of @Output
Forgetting parentheses after @Output
Not initializing EventEmitter with new keyword
3. Given this child component code:
@Output() change = new EventEmitter<number>();
updateValue() {
this.change.emit(42);
}
What will the parent component receive when updateValue() is called?
medium
A. An event with value 42
B. An event with value 'updateValue'
C. No event emitted
D. An error because emit needs a string
Solution
Step 1: Understand what emit does
The emit method sends the given value (here 42) as an event payload to the parent.
Step 2: Check the emitted value type
The emitter is typed as number and emits 42, so the parent receives 42.
Final Answer:
An event with value 42 -> Option A
Quick Check:
emit(42) sends 42 to parent [OK]
Hint: emit(value) sends that value to parent [OK]
Common Mistakes:
Assuming emit sends method name instead of value
Thinking emit requires string only
Believing no event is sent without explicit subscription
4. Identify the error in this child component code snippet:
@Output notify = new EventEmitter<string>();
send() {
this.notify.emit('hello');
}
medium
A. Missing parentheses after @Output decorator
B. EventEmitter should not have a type parameter
C. emit method cannot send strings
D. notify should be private
Solution
Step 1: Check @Output decorator syntax
The @Output decorator requires parentheses: @Output().
Step 2: Verify other parts
Type parameter on EventEmitter is allowed, emit can send strings, and notify can be public.
Final Answer:
Missing parentheses after @Output decorator -> Option A
Quick Check:
@Output() needs parentheses [OK]
Hint: Always write @Output() with parentheses [OK]
Common Mistakes:
Omitting parentheses after @Output
Thinking EventEmitter can't have types
Assuming emit only accepts numbers
5. You want a child component to send a complex object to its parent when a button is clicked. Which approach correctly implements this?