










































































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 main purpose of the polyfills.ts file in an Angular project? A) Bootstrapping the application B) Providing compatibility for older browsers C) Defining routes D) Specifying environment variables Answer: B Explanation: polyfills.ts ensures Angular apps work across browsers by including necessary polyfills for missing JS features. Question 2. Which Angular CLI command initializes a new Angular workspace and project? A) ng serve B) ng build C) ng new D) ng generate Answer: C Explanation: ng new creates a new Angular workspace and a starter project. Question 3. What does the main.ts file do in an Angular application? A) Manages module imports B) Sets up polyfills C) Bootstraps the root module D) Defines component styles Answer: C Explanation: main.ts is responsible for bootstrapping AppModule, starting the application.
Question 4. Which file manages TypeScript configuration for the whole Angular workspace? A) tsconfig.app.json B) tsconfig.spec.json C) angular.json D) tsconfig.json Answer: D Explanation: tsconfig.json sets base TypeScript configuration for the workspace. Question 5. What is the difference between workspace and project in angular.json? A) Workspace is for tests only B) Workspace can contain multiple projects C) Project is for global settings D) No difference Answer: B Explanation: A workspace may contain multiple projects (apps and/or libraries) as defined in angular.json. Question 6. Which flag is used with ng build for production optimization? A) --dev B) --watch C) --prod D) --test Answer: C Explanation: ng build --prod applies production optimizations like AOT, minification, and tree-shaking.
Question 10. What mechanism does Angular use to optimize large applications by loading modules on demand? A) Preloading B) Lazy Loading C) Eager Loading D) Static Loading Answer: B Explanation: Lazy loading loads feature modules only when their routes are accessed, improving performance. Question 11. What is the main role of the Shared Module in Angular architecture? A) Holding root components B) Providing reusable components, directives, and pipes C) Managing HTTP calls D) Defining application routes Answer: B Explanation: Shared Module groups reusable code (components, directives, pipes) for use across feature modules. Question 12. Which change detection strategy checks only when input properties change or events occur? A) Default B) OnPush C) Manual D) Detached Answer: B
Explanation: OnPush strategy triggers change detection only for input changes or explicit events, improving efficiency. Question 13. What is ChangeDetectorRef used for in Angular? A) Managing routes B) Manually triggering change detection C) Loading modules D) Handling HTTP requests Answer: B Explanation: ChangeDetectorRef allows developers to manually control change detection, useful for performance optimization. Question 14. What is Zone.js responsible for in Angular applications? A) Handling HTTP requests B) Polyfills for ES C) Tracking asynchronous events and triggering change detection D) Routing navigation Answer: C Explanation: Zone.js intercepts async operations, notifying Angular to run change detection when needed. Question 15. Which lifecycle hook is best for initializing component data when the component is created? A) ngOnInit B) ngOnDestroy C) ngAfterViewInit D) ngDoCheck
Answer: B Explanation: @Input marks a property to receive values from a parent component. Question 19. How does @Output decorator function in Angular? A) Inputs data B) Exports modules C) Emits custom events to parent components D) Imports modules Answer: C Explanation: @Output allows a child component to emit events to its parent. Question 20. What is EventEmitter used for in Angular components? A) Receiving events B) Emitting events C) Validating data D) Managing routing Answer: B Explanation: EventEmitter is used to create custom events and emit data from child to parent components. Question 21. Which technique allows a parent component to access a child component’s instance directly? A) @Input B) @Output C) ViewChild D) NgFor
Answer: C Explanation: ViewChild decorator allows parent components to access and interact with child component instances. Question 22. What does NgIf directive do? A) Loops through items B) Conditionally adds/removes elements from the DOM C) Switches between templates D) Styles elements Answer: B Explanation: NgIf adds or removes elements based on a boolean expression. Question 23. How does NgFor improve performance with trackBy? A) Always recreates items B) Tracks items by index only C) Identifies items with a custom function to minimize DOM changes D) Disables change detection Answer: C Explanation: trackBy lets NgFor identify items uniquely, reducing unnecessary DOM manipulations. Question 24. Which built-in directive is used to apply CSS classes dynamically? A) NgStyle B) NgClass C) NgFor D) NgSwitch
Explanation: TemplateRef and ViewContainerRef allow developers to manipulate the DOM structure for custom structural directives. Question 28. What built-in pipe would you use to format a date in Angular templates? A) DecimalPipe B) CurrencyPipe C) DatePipe D) AsyncPipe Answer: C Explanation: DatePipe formats date values in Angular templates. Question 29. Which pipe would you use to format a number as currency? A) DatePipe B) CurrencyPipe C) DecimalPipe D) JsonPipe Answer: B Explanation: CurrencyPipe formats numbers as currency using locale information. Question 30. What is the main difference between pure and impure custom pipes? A) Pure pipes run only when input changes, impure pipes run on every change detection cycle B) Pure pipes can’t be created C) Impure pipes are faster D) Pure pipes don’t accept parameters Answer: A
Explanation: Pure pipes execute only when their inputs change, while impure pipes run on every change detection cycle. Question 31. How does Angular support internationalization (i18n) in templates? A) By using only English B) With built-in i18n tags and CLI extraction tools C) Via manual translation D) No i18n support Answer: B Explanation: Angular supports i18n via special markup tags and CLI tools for extracting/translating messages. Question 32. What is the role of the Angular dependency injection hierarchy? A) Manages routing B) Controls how injectors resolve dependencies at various levels (root, platform, element) C) Handles forms D) Optimizes performance Answer: B Explanation: The DI hierarchy determines how services are provided and shared throughout the app. Question 33. Which provider configuration lets you provide a service using a custom class? A) useValue B) useClass C) useFactory D) useExisting Answer: B
Question 37. How can you provide a service at a component level? A) By adding it to the component’s providers array B) Using providedIn: 'root' C) In angular.json D) In index.html Answer: A Explanation: Including a service in a component’s providers array scopes it to that component instance. Question 38. What pattern is used by services provided at the root level in Angular? A) Observer B) Factory C) Singleton D) Prototype Answer: C Explanation: Root-provided services are singleton, meaning only one instance exists across the application. Question 39. Which Angular module is required for using HttpClient? A) FormsModule B) BrowserModule C) HttpClientModule D) RouterModule Answer: C Explanation: HttpClientModule enables HTTP communication capabilities in Angular apps.
Question 40. What RxJS operator is commonly used for HTTP error handling in Angular? A) filter B) catchError C) map D) mergeMap Answer: B Explanation: catchError is used to handle errors in observable streams, such as HTTP requests. Question 41. How do you create a custom HTTP interceptor in Angular? A) Implement CanActivate B) Create a class implementing HttpInterceptor C) Use @Input D) Use ngOnInit Answer: B Explanation: Custom HTTP interceptors implement the HttpInterceptor interface to intercept and modify HTTP requests/responses. Question 42. What method is used to define application routes in Angular? A) RouterModule.forRoot() B) NgModule.forRoot() C) HttpClientModule.forRoot() D) BrowserModule.forRoot() Answer: A Explanation: RouterModule.forRoot() sets up top-level application routes.
Question 46. What does CanDeactivate guard do? A) Prevents route loading B) Checks if user can leave a route/component C) Resolves route data D) Handles authentication Answer: B Explanation: CanDeactivate guard decides if navigation away from a component should proceed. Question 47. Which guard checks access to child routes? A) CanActivateChild B) CanDeactivate C) CanLoad D) Resolve Answer: A Explanation: CanActivateChild evaluates access to child routes of a parent route. Question 48. What is the purpose of the Resolve guard? A) Prevents navigation B) Fetches data before activating a route C) Handles HTTP errors D) Validates forms Answer: B Explanation: Resolve guard retrieves and injects data before route activation. Question 49. How can lazy loading be implemented for feature modules?
A) Import module in AppModule B) Use loadChildren property in route configuration C) Add feature module to providers D) Use ngOnInit Answer: B Explanation: loadChildren property in routes enables lazy loading of feature modules. Question 50. What are named outlets used for in Angular routing? A) Styling elements B) Rendering multiple routes/views simultaneously C) Handling HTTP requests D) Managing forms Answer: B Explanation: Named outlets allow multiple views to be displayed in different areas of the template. Question 51. Which Router method is used for navigation based on route configuration? A) navigateByUrl B) navigate C) go D) redirect Answer: B Explanation: router.navigate() method programmatically navigates based on route configuration. Question 52. What is the difference between Observables and Promises? A) Promises support multiple values
C) Only supports HTTP D) Manages routing Answer: B Explanation: ReplaySubject stores and replays specified number of previous values to new subscribers. Question 56. What is the use of the map operator in RxJS? A) Filtering values B) Transforming emitted values C) Merging streams D) Error handling Answer: B Explanation: map transforms each value emitted by an Observable according to a projection function. Question 57. Which operator is best for chaining HTTP requests that depend on each other? A) forkJoin B) switchMap C) filter D) take Answer: B Explanation: switchMap cancels previous requests and switches to a new observable, ideal for dependent HTTP calls. Question 58. What does combineLatest operator do? A) Merges all values B) Emits the latest values from multiple observables as an array
C) Ignores new values D) Filters nulls Answer: B Explanation: combineLatest emits the latest values from all combined observables whenever any observable emits. Question 59. How can you prevent memory leaks when subscribing to Observables in Angular? A) Never unsubscribe B) Use takeUntil or AsyncPipe C) Use only Promises D) Use map Answer: B Explanation: takeUntil and AsyncPipe help manage subscriptions and automatically unsubscribe to prevent leaks. Question 60. What does the AsyncPipe do in Angular templates? A) Synchronously fetches data B) Automatically subscribes and unsubscribes to observables or promises C) Validates forms D) Handles routing Answer: B Explanation: AsyncPipe manages observable or promise subscriptions in the template, cleaning up automatically. Question 61. What is required to use template-driven forms in Angular? A) ReactiveFormsModule