
















































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!

















































Q1: What is Angular primarily used for? A. Mobile application development B. Server-side programming C. Web application development D. Desktop application development Answer: C Explanation: Angular is a platform and framework for building web applications using HTML and TypeScript. Q2: Which language is Angular written in? A. JavaScript B. TypeScript C. Python D. Java Answer: B Explanation: Angular is built with TypeScript, a superset of JavaScript that adds static types. Q3: What command is used to create a new Angular project using Angular CLI? A. ng new B. ng generate C. ng create D. ng init Answer: A Explanation: The Angular CLI command “ng new” creates a new Angular project. Q4: Which of the following is a key feature of Angular? A. One-way data binding only B. Dependency injection C. Lack of modularity D. No support for mobile development Answer: B Explanation: Dependency injection is one of Angular’s core features, enabling efficient service and component communication. Q5: Compared to other frameworks, Angular emphasizes a full-fledged framework approach. Which of the following best explains this? A. It provides a minimal library for DOM manipulation.
B. It includes built-in solutions for routing, forms, HTTP, and more. C. It requires external libraries for most functionalities. D. It is only used for building server applications. Answer: B Explanation: Angular is a complete framework with built-in functionalities for routing, forms, HTTP communications, and more. Q6: In Angular, what is a component? A. A service for handling HTTP requests B. A building block that controls a portion of the UI C. A type of directive used for styling D. A module that defines application routes Answer: B Explanation: Components are the basic UI building blocks in Angular that control a part of the screen called a view. Q7: Which Angular lifecycle hook is invoked right after the component’s data-bound properties have been initialized? A. ngOnDestroy B. ngAfterViewInit C. ngOnInit D. ngDoCheck Answer: C Explanation: The ngOnInit hook is called after Angular has initialized all data-bound properties. Q8: What is the purpose of the EventEmitter in Angular? A. To send HTTP requests B. To create custom pipes C. To facilitate communication from child to parent components D. To format dates Answer: C Explanation: EventEmitter is used in Angular to emit events, allowing child components to communicate with parent components. Q9: Which of the following best describes Angular’s view encapsulation? A. It prevents component styles from leaking out to the rest of the application. B. It isolates data binding to specific components. C. It encapsulates HTTP services for security. D. It prevents components from being reused.
Q14: How do you implement two-way data binding in Angular? A. Using [()] syntax with ngModel B. Using {{}} interpolation only C. Using () event binding only D. Using [property] binding only Answer: A Explanation: The combination of property and event binding using the [(ngModel)] syntax enables two-way data binding in Angular. Q15: What is the primary role of services in Angular? A. To provide UI elements B. To share data and business logic across components C. To render templates D. To manage component lifecycle hooks Answer: B Explanation: Services are used to encapsulate business logic and share data across multiple components in Angular. Q16: What is Dependency Injection (DI) in Angular? A. A technique to combine multiple components B. A way to inject data directly into HTML C. A design pattern for supplying a component with its dependencies D. A method to dynamically compile modules Answer: C Explanation: Dependency Injection is a design pattern in Angular that allows components and services to declare dependencies, which are then provided by Angular’s injector. Q17: How do you register a service for DI in Angular? A. Using the providers array in NgModule or component decorator B. Directly importing it in the component file C. Including it in the bootstrap array D. Declaring it in the template Answer: A Explanation: Services are registered by adding them to the providers array in an NgModule or a component decorator for Angular’s dependency injection system. Q18: What does the @Injectable decorator in Angular indicate? A. That the class is a component B. That the class can be injected as a dependency C. That the class is a directive D. That the class is used for animations
Answer: B Explanation: The @Injectable decorator tells Angular that the class can be used as a dependency and injected where needed. Q19: Which Angular feature allows for defining route paths and their associated components? A. Angular Universal B. RouterModule C. NgModule D. ComponentFactory Answer: B Explanation: The RouterModule is used to configure routes that map URL paths to components. Q20: Which of the following is used to navigate programmatically in an Angular application? A. routerLink directive B. router.navigate method C. HTTP client D. ngSwitch directive Answer: B Explanation: The router.navigate method is used in code to programmatically change routes in an Angular application. Q21: What is the role of router guards such as CanActivate in Angular? A. To animate route transitions B. To control access to routes based on conditions C. To pre-load data D. To generate HTML templates Answer: B Explanation: Router guards like CanActivate help in determining whether a route can be activated based on logic such as user authentication. Q22: What is lazy loading in Angular routing? A. Loading all modules at once B. Loading modules on demand when a route is accessed C. Delaying HTTP requests D. Preloading all application data at startup Answer: B Explanation: Lazy loading means that modules are loaded only when needed, which improves initial load time.
Answer: C Explanation: The catchError operator is used to handle errors that occur during an observable stream, such as an HTTP request. Q28: Which RxJS operator is typically used to transform emitted values in an observable? A. filter B. map C. switchMap D. debounceTime Answer: B Explanation: The map operator is used to transform each emitted value from an observable. Q29: What is the purpose of NgRx in Angular? A. To create animations B. To manage state using a Redux-style architecture C. To improve HTTP performance D. To generate templates Answer: B Explanation: NgRx is a library for managing application state in Angular using a Redux-style pattern involving stores, actions, reducers, and effects. Q30: In NgRx, what is the function of a reducer? A. To dispatch actions B. To determine how the state changes in response to actions C. To create new observables D. To subscribe to store updates Answer: B Explanation: A reducer is a pure function that takes the current state and an action, and returns a new state based on that action. Q31: Which testing framework is most commonly used with Angular for unit tests? A. Mocha B. Jasmine C. Jest D. QUnit Answer: B Explanation: Angular applications typically use Jasmine as the testing framework, often in conjunction with Karma as the test runner. Q32: What is the role of TestBed in Angular testing? A. To simulate HTTP requests B. To configure and initialize an Angular testing environment
C. To generate dynamic components D. To handle routing Answer: B Explanation: TestBed is Angular’s primary API for writing unit tests, enabling you to configure and initialize a testing module. Q33: Which Angular tool assists in debugging component trees and performance? A. Angular CLI B. Angular Universal C. Angular Augury D. RxJS DevTools Answer: C Explanation: Angular Augury is a Chrome extension that helps developers inspect and debug Angular applications. Q34: What does Ahead-of-Time (AOT) compilation do in Angular? A. Compiles Angular templates in the browser at runtime B. Pre-compiles Angular code during build time C. Disables dependency injection D. Increases application load time Answer: B Explanation: AOT compilation pre-compiles Angular components and templates during the build process, leading to faster rendering in the browser. Q35: How does lazy loading improve the performance of an Angular application? A. By loading all modules immediately B. By reducing the initial load time through on-demand module loading C. By caching all HTTP requests D. By eliminating dependency injection Answer: B Explanation: Lazy loading defers the loading of modules until they are needed, which decreases the initial bundle size and speeds up application load time. Q36: What is a common security practice to prevent Cross-Site Scripting (XSS) in Angular? A. Using innerHTML to render data B. Trusting all user inputs C. Angular’s built-in sanitization of inputs D. Disabling data binding
Q41: What is the significance of the “providers” array in an Angular module? A. It declares component selectors B. It registers services for dependency injection C. It configures routing D. It holds HTML templates Answer: B Explanation: The “providers” array in an NgModule is used to register services, making them available for dependency injection throughout the application. Q42: Which Angular directive dynamically adds or removes an element from the DOM based on a condition? A. ngSwitch B. ngIf C. ngFor D. ngStyle Answer: B Explanation: The ngIf directive conditionally adds or removes elements from the DOM. Q43: What does the ngOnDestroy lifecycle hook do in an Angular component? A. Initializes data-bound properties B. Cleans up resources before the component is destroyed C. Renders the component template D. Binds event listeners for data updates Answer: B Explanation: ngOnDestroy is used to perform cleanup tasks like unsubscribing from observables or detaching event handlers before the component is removed. Q44: In Angular, what is the function of the routerLink directive? A. It styles links in the application B. It binds a URL path to an anchor element for navigation C. It creates a new component D. It configures HTTP requests Answer: B Explanation: The routerLink directive binds a URL path to an anchor element, enabling navigation within an Angular application. Q45: What is one key advantage of reactive forms over template-driven forms in Angular? A. They do not require any form validation B. They allow more dynamic control and validation of form state C. They are easier to set up for simple forms D. They automatically generate templates
Answer: B Explanation: Reactive forms provide a more explicit and dynamic way to manage form state and validations, making them better suited for complex forms. Q46: What is the primary benefit of using Angular CLI in development? A. It automatically writes application code B. It provides a set of tools to generate, build, test, and deploy Angular applications C. It replaces the need for Node.js D. It only works with Angular Universal Answer: B Explanation: Angular CLI simplifies development by automating tasks such as project generation, building, testing, and deployment. Q47: Which Angular directive is used to add or remove CSS classes based on conditions? A. ngStyle B. ngClass C. ngSwitch D. ngBind Answer: B Explanation: The ngClass directive dynamically adds or removes CSS classes based on the evaluation of an expression. Q48: How does Angular handle dependency injection internally? A. By using a global variable B. Through a hierarchical injector system C. By manual object creation D. By reading from the HTML template Answer: B Explanation: Angular uses a hierarchical injector system to manage dependency injection, ensuring that dependencies are provided at different levels of the application. Q49: Which of the following is NOT a built-in Angular directive? A. ngFor B. ngIf C. ngSwitch D. ngBindHtml Answer: D Explanation: While Angular provides many built-in directives, ngBindHtml is not one of them in Angular (it was available in AngularJS). Q50: What is the function of the FormBuilder service in Angular reactive forms? A. To build HTML templates
Answer: B Explanation: Using providedIn: 'root' in the @Injectable decorator registers the service as a singleton at the application level. Q55: Which of the following correctly describes Angular’s change detection strategy? A. It always uses a manual refresh method B. It can be optimized using the OnPush strategy to check only when inputs change C. It does not support change detection D. It requires external libraries for change tracking Answer: B Explanation: Angular’s OnPush change detection strategy optimizes performance by checking for changes only when component inputs change. Q56: What is the benefit of using the trackBy function in ngFor loops? A. It disables change detection B. It enhances performance by identifying items uniquely C. It binds additional styles D. It simplifies dependency injection Answer: B Explanation: The trackBy function helps Angular identify unique items in a list, improving performance when rendering large lists. Q57: Which Angular feature allows for offline support by caching application assets? A. Service Workers B. Angular CLI C. Lazy loading D. Dependency injection Answer: A Explanation: Service Workers enable offline support by caching assets and API responses for Angular applications. Q58: What is the primary purpose of Angular Elements? A. To build server-side applications B. To create reusable web components that work in non-Angular environments C. To manage application state D. To perform unit testing Answer: B Explanation: Angular Elements allows developers to create custom elements (web components) that can be used in any web application regardless of the framework. Q59: In Angular, how do you typically handle route parameters? A. By using local storage
B. By injecting ActivatedRoute into the component C. By using a global variable D. By declaring them in the NgModule providers array Answer: B Explanation: The ActivatedRoute service provides access to route parameters and query parameters within a component. Q60: What is the primary advantage of using Angular’s reactive forms? A. They automatically generate HTML templates B. They allow for a more programmatic approach to form management and validation C. They require less code than template-driven forms for all cases D. They eliminate the need for Angular modules Answer: B Explanation: Reactive forms offer a more flexible, scalable, and programmatic way to build and validate forms compared to template-driven forms. Q61: Which of the following Angular directives is used to dynamically switch between views? A. ngSwitch B. ngIf C. router-outlet D. ngComponentOutlet Answer: C Explanation: The router-outlet directive acts as a placeholder that Angular dynamically fills based on the current route. Q62: What does the HttpClient’s get() method return? A. A Promise B. An Observable C. A plain JavaScript object D. A callback function Answer: B Explanation: The HttpClient’s get() method returns an Observable, which allows for asynchronous data handling. Q63: Which Angular CLI command is used to serve an application during development? A. ng build B. ng serve C. ng deploy D. ng start
B. ngAfterContentInit C. ngOnChanges D. ngOnDestroy Answer: D Explanation: The ngOnDestroy lifecycle hook is intended for cleanup logic, such as unsubscribing from observables. Q69: Which of the following is true about Angular modules? A. They are only used for lazy loading B. They help in organizing an application into cohesive blocks of functionality C. They are optional in Angular applications D. They replace the need for components Answer: B Explanation: Angular modules are used to organize code into cohesive blocks, grouping related components, directives, pipes, and services. Q70: How is data typically passed from a parent component to a child component in Angular? A. Using Output and EventEmitter B. Using Input properties C. Using services only D. By directly modifying the child’s variables Answer: B Explanation: Data is passed from parent to child components using the @Input decorator to define input properties. Q71: What does the “ngModel” directive facilitate in Angular? A. One-way data binding from view to component B. Two-way data binding between the component and the view C. Creating custom directives D. Handling HTTP requests Answer: B Explanation: The ngModel directive enables two-way data binding, synchronizing the component’s data with the view. Q72: In Angular forms, what is a FormArray used for? A. To hold a dynamic collection of FormControl, FormGroup, or other FormArray instances B. To store CSS classes C. To define static form controls only D. To wrap HTML elements
Answer: A Explanation: A FormArray is a reactive form structure that manages an array of form controls, useful for dynamic forms. Q73: Which RxJS operator would you use to switch to a new observable when a value changes, cancelling the previous one? A. mergeMap B. switchMap C. concatMap D. exhaustMap Answer: B Explanation: The switchMap operator cancels the previous observable and switches to the new observable when a new value is emitted. Q74: What is the primary function of the Angular CLI command “ng build”? A. To run unit tests B. To compile the application into an output folder for deployment C. To generate a new module D. To serve the application locally Answer: B Explanation: The “ng build” command compiles the application and produces the necessary files for deployment. Q75: Which of the following is NOT an advantage of Angular’s dependency injection system? A. It makes components more modular B. It simplifies the testing process C. It automatically optimizes CSS files D. It promotes reusability of services Answer: C Explanation: Angular’s dependency injection system does not handle CSS optimization; it primarily deals with component and service instantiation. Q76: How can you create a custom directive in Angular? A. By using the @Component decorator B. By using the @Directive decorator C. By writing a plain JavaScript function D. By extending the Angular core module Answer: B Explanation: Custom directives in Angular are created using the @Directive decorator.
Answer: B Explanation: Angular automatically sanitizes potentially unsafe data bindings, which helps secure data displayed in templates. Q82: How do you perform a POST request using Angular’s HttpClient? A. httpClient.get() B. httpClient.put() C. httpClient.post() D. httpClient.delete() Answer: C Explanation: The httpClient.post() method is used to send data to a server via a POST request. Q83: Which Angular CLI command would you use to run unit tests? A. ng test B. ng serve C. ng build D. ng deploy Answer: A Explanation: The “ng test” command is used to run unit tests using tools like Karma and Jasmine. Q84: In Angular, what is the purpose of a selector in a component? A. To define the component’s style encapsulation B. To specify the custom HTML tag for the component C. To configure routing D. To enable dependency injection Answer: B Explanation: The selector property in a component’s metadata defines the custom HTML tag that represents that component. Q85: What does the term “data binding” refer to in Angular? A. Binding CSS files to components B. Synchronizing data between the model and the view C. Combining multiple components into one D. Merging JavaScript libraries Answer: B Explanation: Data binding in Angular refers to the process of synchronizing the data in the component (model) with the view (template). Q86: How can you pass data from a child component back to a parent component? A. Using the @Input decorator B. Using the @Output decorator and EventEmitter
C. By directly accessing the parent’s properties D. Through the Angular CLI Answer: B Explanation: The @Output decorator along with EventEmitter is used for passing data from a child component to a parent component. Q87: Which of the following best describes reactive programming with RxJS in Angular? A. Writing synchronous code B. Working with streams of asynchronous events C. Disabling event handling D. Creating static HTML pages Answer: B Explanation: Reactive programming with RxJS involves working with streams of data and asynchronous events, allowing complex event handling. Q88: What does the “async” pipe in Angular do? A. Converts synchronous code to asynchronous B. Automatically subscribes and unsubscribes from observables C. Runs code on a separate thread D. Disables change detection Answer: B Explanation: The async pipe subscribes to an observable or promise and returns the latest value, handling subscription management automatically. Q89: Which Angular feature helps in improving SEO by enabling server-side rendering? A. Angular CLI B. Angular Universal C. Lazy loading D. NgRx Answer: B Explanation: Angular Universal provides server-side rendering capabilities, which improve SEO by rendering pages on the server before sending them to the client. Q90: What is a key benefit of using NgRx for state management in Angular? A. It reduces the need for services B. It centralizes state in a single store for predictable state management C. It eliminates the use of observables D. It automatically creates user interfaces Answer: B Explanation: NgRx centralizes the application state in a store, making state changes predictable and easier to manage.