In Angular, components are the building blocks of an application. They define the UI structure, handle user interactions, and manage data flow. Communication between components is crucial for sharing data and achieving modularity.
This MCQ set will help you understand component structure, lifecycle hooks, and data-sharing techniques, which are essential for interview preparation and real-world Angular development.
1.) What is an Angular component?
A) A JavaScript function used to manipulate the DOM
B) A UI building block with an HTML template, TypeScript class, and CSS styles
C) A module that controls application routing
D) A predefined service in Angular
2.) How do you define a component in Angular?
A) Using the @Component decorator
B) Using the @Directive decorator
C) Using the @Injectable decorator
D) Using the @Module decorator
3.) What is the purpose of the selector property in a component?
A) To define the name of the component class
B) To bind the component to a module
C) To set component styles
D) To specify how the component is referenced in templates
4.) Which lifecycle hook is used for cleanup operations?
A) ngOnInit()
B) ngOnChanges()
C) ngOnDestroy()
D) ngAfterViewInit()
5.) How many components can an Angular application have?
A) Only one
B) Only three
C) Only ten
D) Unlimited
6.) Which component acts as the root component in an Angular project?
A) app.module.ts
B) main.ts
C) app.component.ts
D) index.html
7.) What is the default way to pass data from a parent to a child component in Angular?
A) Using @Input decorator
B) Using @Output decorator
C) Using a service
D) Using local storage
8.) How does a child component communicate with a parent component?
A) Using @Input decorator
B) Using @Output and EventEmitter
C) Using @Injectable service
D) Using @ChildComponent decorator
9.) Which Angular lifecycle hook is called only once when the component is created?
A) ngOnInit()
B) ngOnDestroy()
C) ngAfterViewInit()
D) ngOnChanges()
10.) What is the use of ngOnDestroy() lifecycle hook?
A) It initializes the component
B) It triggers change detection
C) It runs when the view is updated
D) It performs cleanup tasks before a component is destroyed
Related