Angular MCQs – Components and Communication

11.) What is the purpose of ViewChild in Angular?

A) To get a reference to a child component or DOM element
B) To define a component as a child of another
C) To pass data from a child to a parent
D) To create a new component dynamically

Answer: Option A

Explanation: @ViewChild allows a parent component to access a child component’s properties and methods.

12.) How can two unrelated components communicate in Angular?

A) Using @Input
B) Using @Output
C) Using a shared service
D) Using local variables

Answer: Option C

Explanation: A shared service with a Subject or BehaviorSubject can enable communication between unrelated components.

13.) What happens if a component is not declared in an Angular module?

A) It will throw an error
B) It will still work
C) It will be converted into a directive
D) It will be ignored by Angular

Answer: Option A

Explanation: Every component must be declared in an NgModule for it to be recognized by Angular.

14.) What happens when a component is destroyed?

A) It gets hidden but remains in memory
B) It is removed from the DOM and memory
C) It stops receiving input properties
D) It only removes its template but keeps its logic in memory

Answer: Option B

Explanation: When a component is destroyed, Angular removes it from the DOM, and ngOnDestroy() can be used for cleanup.

15.) What is the main benefit of OnPush change detection strategy?

A) It improves performance by reducing unnecessary checks
B) It allows direct DOM manipulation
C) It runs change detection continuously
D) It disables change detection

Answer: Option A

Explanation: ChangeDetectionStrategy.OnPush updates only when the component’s input changes, reducing performance overhead.

16.) What is the primary use of Angular services?

A) To create reusable components
B) To define routes in the application
C) To manage application data and business logic
D) To apply CSS styling

Answer: Option C

Explanation: Services are used for data management, API calls, and sharing logic between components.

17.) What is the correct way to pass data to a child component?

A) Using @ViewChild
B) Using @Input
C) Using @Output
D) Using a service

Answer: Option B

Explanation: The @Input decorator is used in a child component to receive data from its parent.

18.) What happens if you use @Input() in a parent component?

A) The child component will receive data
B) The parent component will receive data
C) The application will crash
D) It has no effect

Answer: Option D

Explanation: @Input() is meant to be used in child components to receive data from parent components.

19.) What does @Output in Angular do?

A) Allows a parent component to pass data to a child component
B) Allows a child component to send data to its parent component
C) Creates a new component dynamically
D) Performs dependency injection

Answer: Option B

Explanation: The @Output() decorator, combined with EventEmitter, is used for child-to-parent component communication.

20.) How do you trigger an event using EventEmitter in Angular?

A) this.eventName.trigger()
B) this.eventName.send()
C) this.eventName.emit(value)
D) this.eventName.broadcast(value)

Answer: Option C

Explanation: emit(value) is used to send data from a child component to a parent component via an event.

Leave a Reply

Your email address will not be published. Required fields are marked *