









































































Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!










































































Question 1. What is the primary purpose of Angular modules? A) To define CSS styles B) To group related code and functionality C) To manage HTTP requests D) To handle animations Answer: B Explanation: Angular modules group related components, directives, pipes, and services, making the application more organized and maintainable. Question 2. Which decorator is used to define a component in Angular? A) @NgModule B) @Injectable C) @Component D) @Directive Answer: C Explanation: The @Component decorator is used to define a component, specifying its template, selector, and metadata. Question 3. What is the root module in an Angular application typically called? A) MainModule B) AppModule C) RootModule D) StartModule Answer: B Explanation: The root module is conventionally named AppModule and bootstraps the application.
Question 4. What Angular module must be imported to use common directives like *ngIf and *ngFor in a feature module? A) FormsModule B) RouterModule C) CommonModule D) HttpClientModule Answer: C Explanation: CommonModule provides common directives like *ngIf and *ngFor required in feature modules. Question 5. Which of the following is NOT a type of data binding in Angular? A) Interpolation B) Event Binding C) Two-way Binding D) String Binding Answer: D Explanation: Angular supports interpolation, event binding, and two-way binding, but not "string binding." Question 6. What does the @Injectable decorator signify in Angular? A) The class is a component B) The class can be injected as a service C) The class is a module D) The class is a directive Answer: B Explanation: @Injectable marks a class as available to be provided and injected as a dependency.
Question 10. Which lifecycle hook is called after Angular has initialized all data-bound properties of a component? A) ngOnInit B) ngOnDestroy C) ngAfterViewInit D) ngDoCheck Answer: A Explanation: ngOnInit is triggered once after the first ngOnChanges, initializing the component. Question 11. What is the purpose of the Angular CLI command ng serve? A) To deploy the app to production B) To start a local development server C) To test the application D) To generate a new service Answer: B Explanation: ng serve runs a local development server and watches for file changes. Question 12. Which ES6 feature allows you to define variables whose values cannot be changed? A) let B) const C) var D) static Answer: B Explanation: const is used to declare constants whose values cannot be reassigned.
Question 13. What does the Angular CLI command ng build --prod do? A) Builds the app for testing B) Builds the app for production optimization C) Runs end-to-end tests D) Starts the development server Answer: B Explanation: ng build --prod creates an optimized production build, enabling Ahead-of-Time compilation and more. Question 14. What is the main purpose of BrowserModule in Angular? A) To enable routing B) To provide browser-specific services and directives C) To handle HTTP requests D) To add animation support Answer: B Explanation: BrowserModule is required for all applications running in the browser and provides essential services. Question 15. What is the correct way to define a template reference variable in Angular templates? A) $var B) #var C) @var D) &var Answer: B Explanation: Template reference variables are defined using the # symbol, like #myInput.
A) To define root-level routes for the application B) To configure lazy loading C) To declare feature module routes D) To inject HTTP services Answer: A Explanation: forRoot() is used for root-level route configuration in the main app module. Question 20. Which lifecycle hook is invoked just before Angular destroys the component? A) ngOnInit B) ngOnDestroy C) ngAfterViewInit D) ngDoCheck Answer: B Explanation: ngOnDestroy is called right before Angular removes and destroys the component. Question 21. What is the correct way to inject a service into a component’s constructor? A) Direct import B) Using @Injectable in the component C) Adding it to the constructor parameters D) Using ngModule Answer: C Explanation: Services are injected by adding them as parameters in the component’s constructor. Question 22. What does the *ngFor directive do? A) Iterates over an array to create views for each item
B) Conditionally displays an element C) Switches between views D) Styles an element dynamically Answer: A Explanation: *ngFor is a structural directive used to iterate over collections and render templates. Question 23. In Reactive Forms, which class represents a single form control? A) FormArray B) FormGroup C) FormControl D) NgModel Answer: C Explanation: FormControl represents a single input element in a reactive form. Question 24. What is the purpose of the map operator in RxJS? A) To filter values B) To transform values emitted by an observable C) To merge multiple observables D) To delay emissions Answer: B Explanation: map transforms each value emitted by an observable according to the specified function. Question 25. How do you define a custom attribute directive in Angular? A) By using @Component B) By using @Directive
D) Error Answer: B Explanation: The arrow function returns the sum 2 + 2, which is 4. Question 29. How do you specify a required field in a template-driven form? A) [required]="true" B) required C) required="true" D) [isRequired]="true" Answer: B Explanation: Using the required attribute in the input element marks the field as required. Question 30. What is the Angular CLI command to add a new service? A) ng create service B) ng generate service C) ng make service D) ng add service Answer: B Explanation: ng generate service (ng g s) generates a new service file. Question 31. What is the main function of the EventEmitter class in Angular? A) To receive events from the parent B) To emit custom events from child to parent components C) To log events D) To handle HTTP events
Answer: B Explanation: EventEmitter is used to create custom events to send data from child to parent components. Question 32. How do you configure a route with a dynamic parameter in Angular? A) { path: 'user', component: UserComponent } B) { path: 'user/:id', component: UserComponent } C) { path: 'user?id', component: UserComponent } D) { path: 'user/{id}', component: UserComponent } Answer: B Explanation: Dynamic parameters are specified using a colon, as in 'user/:id'. Question 33. Which method is used to navigate programmatically in Angular? A) router.move() B) router.navigate() C) router.go() D) router.push() Answer: B Explanation: router.navigate() is used to navigate programmatically to different routes. Question 34. Which operator in RxJS is used to switch to a new observable and cancel the previous one? A) map B) filter C) switchMap D) mergeMap
Explanation: ngOnDestroy is used to perform cleanup, such as unsubscribing from observables, before the component is destroyed. Question 38. Which file is used for configuring global styles in an Angular project created with the CLI? A) styles.ts B) style.css C) styles.css D) main.css Answer: C Explanation: styles.css is used for global styles in a CLI-generated Angular project. Question 39. What does the async pipe do in Angular templates? A) Subscribes to an observable and returns the latest value B) Runs code asynchronously C) Delays rendering D) Handles promises only Answer: A Explanation: The async pipe subscribes to observables and automatically updates the view with the latest value. Question 40. What is the correct way to apply multiple CSS classes dynamically to an element in Angular? A) [ngClass]="['class1', 'class2']" B) class="{{class1 class2}}" C) [class]="{class1, class2}" D) class="class1, class2"
Answer: A Explanation: [ngClass] allows you to apply multiple classes dynamically as an array or object. Question 41. How do you define a provider for a custom value in Angular’s DI system? A) useNew B) useValue C) useClass D) useFactory Answer: B Explanation: useValue allows you to provide a custom value for injection. Question 42. Which Angular feature allows you to load feature modules only when needed? A) Eager loading B) Lazy loading C) Static loading D) On-demand loading Answer: B Explanation: Lazy loading loads modules on demand, improving performance. Question 43. What is required to use template-driven forms in Angular? A) Import FormsModule B) Import ReactiveFormsModule C) Import CommonModule D) Import BrowserModule Answer: A
Question 47. How do you access a route parameter in a component? A) Inject ActivatedRoute and use snapshot.params B) Use RouterModule C) Use @Input D) Use ngModel Answer: A Explanation: ActivatedRoute provides access to route parameters via the snapshot or observable property. Question 48. Which Angular CLI command updates your Angular project dependencies? A) ng build B) ng serve C) ng update D) ng upgrade Answer: C Explanation: ng update updates Angular and its dependencies to the latest version. Question 49. What is the primary purpose of the CommonModule? A) Provides routing capabilities B) Provides common directives and pipes for feature modules C) Provides testing utilities D) Provides HTTP services Answer: B Explanation: CommonModule includes common directives and pipes that feature modules need.
Question 50. What is the output of the following code: let [x, y] = [5, 10]; console.log(x, y);? A) 10 5 B) 5 10 C) undefined undefined D) [5, 10] Answer: B Explanation: Destructuring assigns 5 to x and 10 to y. Question 51. Which property of FormGroup provides the overall validity status? A) value B) status C) valid D) errors Answer: C Explanation: valid is a boolean property indicating the validity of the entire FormGroup. Question 52. What is the use of the catchError operator in RxJS? A) To stop emissions B) To handle errors in observables and provide fallback logic C) To map emitted values D) To merge observables Answer: B Explanation: catchError is used to handle errors and return a new observable or throw an error.
Question 56. What is the correct way to bind to a DOM event in Angular? A) (click)="doSomething()" B) click="doSomething()" C) [click]="doSomething()" D) (onClick)="doSomething()" Answer: A Explanation: (eventName) syntax binds to DOM events in Angular templates. Question 57. Which file typically contains the main routing configuration? A) app.component.ts B) app.module.ts C) app-routing.module.ts D) main.ts Answer: C Explanation: app-routing.module.ts is used for main routing configuration. Question 58. What does the providedIn: 'root' option in @Injectable do? A) Registers the service locally B) Makes the service a singleton and available throughout the app C) Restricts the service to a component D) Disables the service Answer: B Explanation: providedIn: 'root' makes the service available application-wide as a singleton. Question 59. How do you add a new feature module using Angular CLI?
A) ng create module feature B) ng add module feature C) ng generate module feature D) ng make module feature Answer: C Explanation: ng generate module feature creates a new feature module. Question 60. What does the ngDoCheck lifecycle hook allow you to do? A) Initialize the component B) Detect and act upon changes that Angular doesn't catch by default C) Destroy the component D) Render the template Answer: B Explanation: ngDoCheck is used for custom change detection logic. Question 61. Which Angular module must be imported for Reactive Forms? A) ReactiveFormsModule B) FormsModule C) CommonModule D) RouterModule Answer: A Explanation: ReactiveFormsModule provides all the reactive form directives and services. Question 62. What is the function of the FormArray class in Reactive Forms? A) Represents a group of controls