Master technical and career interviews with structured answers—short definition, real examples, pitfalls, and how to answer in 60–90 seconds.
Short answer: And configuration to manage navigation between views. Explain a bit more ✅ Imports in App: import { RouterModule } from '@angular/router'; You use it with RouterModule.forRoot() (for root module) or RouterM…
Short answer: Examples: <!-- *ngIf --> <div *ngIf="user.isLoggedIn">Welcome, {{ user.name }}</div> <!-- *ngFor --> <li *ngFor="let item of items">{{ item }}</li> Re…
Short answer: Directives are instructions in the DOM. They help Angular extend HTML's capabilities. Types of Directives: Real-world example (ShopNest) A shared CartService is injected into header and product pages so bot…
Short answer: XSS (Cross-Site Scripting) Protection: Angular automatically sanitizes dangerous content in templates (e.g., {{ userInput }}). Explain a bit more Use DomSanitizer for trusted content. Binding syntax prevent…
Short answer: Provide a mock implementation of the service in TestBed using the providers array. Use useClass, useValue, or useFactory to inject mocks. Example code class MockDataService { getData() { return of(['mock da…
Short answer: trackBy is a function used with *ngFor to tell Angular how to track list items uniquely. Why it matters: Without trackBy, Angular recreates DOM elements on each update, causing performance overhead. ✅ Examp…
Short answer: Lazy loading loads feature modules only when needed (e.g., when a user navigates to a route). Benefits: Reduces initial bundle size → faster app startup. Improves performance and user experience. Enables be…
Short answer: gainst XSS and CSRF? XSS (Cross-Site Scripting) Protection: Angular automatically sanitizes dangerous content in templates (e.g., {{ userInput }}). Use DomSanitizer for trusted content. Binding syntax preve…
Short answer: JWT is a compact, URL-safe token format that securely transmits information between parties. Contains a payload with user info and claims, digitally signed. Angular apps use JWT to: Store authentication sta…
Short answer: rray. Use useClass, useValue, or useFactory to inject mocks. class MockDataService { getData() { return of(['mock data']); } } beforeEach(() => { TestBed.configureTestingModule({ providers: [{ provide: D…
Short answer: Comman Purpose ng serve Builds app in memory, runs a dev server, watches files, reloads on changes (for development) ng build Builds app to disk, generates production or development-ready output files Real-…
Short answer: CommonModule provides common directives like *ngIf, *ngFor, ngClass, etc. You import it in feature modules or any module other than the root module. Don’t import BrowserModule in feature modules; instead, i…
Short answer: ngular reuses existing DOM elements instead of recreating them. Real-world example (ShopNest) ShopNest admin can be built in Angular with modules/components, services for API calls, and reactive forms for p…
Short answer: Class Role FormContr ol Tracks value and validation status of a single input FormGroup Groups multiple FormControls into a form FormArray Manages an array of FormControls or FormGroups dynamically Example c…
Short answer: Aspect Constructor ngOnInit Purpose Initializes the class Lifecycle hook, called after constructor Use Case Inject dependencies Fetch data, initialize logic Called By JavaScript engine Angular Example code…
Short answer: Use Ahead-of-Time (AOT) compilation for faster rendering. Explain a bit more Enable production builds (ng build --prod) with optimizations: Minification Tree shaking Dead code elimination Use lazy loading f…
Short answer: Dependency Injection (DI) is a design pattern in which objects receive their dependencies from an external source, not by creating them. Angular has a built-in DI system that allows services to be injected…
Short answer: And faster repeat loads. Optimize images and assets (compress, lazy load). Use OnPush change detection for components to reduce unnecessary UI updates. Avoid memory leaks by unsubscribing from observables.…
Short answer: CustomEvent is a native JavaScript event that allows sending custom data. In Angular, used in event emitters to pass data from child to parent components. Angular wraps this with @Output() and EventEmitter.…
Short answer: NgRx is a Redux-inspired state management library for Angular. Uses Actions, Reducers, Store, and Effects to handle application state predictably. Centralizes state for easy debugging, time-travel, and immu…
Short answer: TestBed: Core Angular testing utility to configure test modules and components. ngMocks: A library built on top of TestBed to simplify mocking and reduce boilerplate by auto-mocking components, directives,…
Short answer: Use the production flag with ng build: ng build --prod This enables: AOT compilation (Ahead-of-Time) Minification and Uglification of code Tree shaking to remove unused code Bundling for fewer HTTP requests…
Short answer: BrowserModule includes services essential for running the app in a browser. It also exports CommonModule. Should only be imported once, in the root AppModule. It sets up things like DOM rendering, sanitizat…
Short answer: ChangeDetectorRef allows you to manually control change detection: detectChanges(): Run change detection immediately. markForCheck(): Mark component to check in next cycle. detach(): Stop change detection f…
Short answer: ngular has a built-in DI system that allows services to be injected into components or other services. constructor(private authService: AuthService) {} Real-Time Example: In an e-commerce app: Inject CartSe…
Angular Angular Tutorial · Angular
Short answer: And configuration to manage navigation between views.
✅ Imports in App: import { RouterModule } from '@angular/router'; You use it with RouterModule.forRoot() (for root module) or RouterModule.forChild() (for feature modules with lazy loading). const routes: Routes = [ { path: '', component: HomeComponent }, { path: 'products', component: ProductListComponent }, { path: 'products/:id', component: ProductDetailComponent }, { path: '**', component: NotFoundComponent } // wildcard route ]; Tools for Managing Routes: Route Guards Route Parameters Lazy Loading Query Params Nested Routes implemented? 🔸 Lazy Loading: Lazy loading is a technique to load feature modules only when needed, improving initial load performance. ✅ Implementation:
ShopNest’s ProductListComponent binds *ngFor to products and uses (click) to add to cart.
Angular Angular Tutorial · Angular
Short answer: Examples: <!-- *ngIf --> <div *ngIf="user.isLoggedIn">Welcome, {{ user.name }}</div> <!-- *ngFor --> <li *ngFor="let item of items">{{ item }}</li> Real-Time Example: In a to-do app, *ngFor is used to loop through tasks and display them.
A shared CartService is injected into header and product pages so both see the same cart count.
Angular Angular Tutorial · Angular
Short answer: Directives are instructions in the DOM. They help Angular extend HTML's capabilities. Types of Directives:
A shared CartService is injected into header and product pages so both see the same cart count.
Angular Angular Tutorial · Angular
Short answer: XSS (Cross-Site Scripting) Protection: Angular automatically sanitizes dangerous content in templates (e.g., {{ userInput }}).
Use DomSanitizer for trusted content. Binding syntax prevents direct HTML injection. CSRF (Cross-Site Request Forgery) Protection: Angular’s HttpClient works with backend CSRF tokens. Common approach: Backend sends CSRF token, Angular sends it back via headers or cookies. Developers must implement token handling in interceptors.
Angular Angular Tutorial · Angular
Short answer: Provide a mock implementation of the service in TestBed using the providers array. Use useClass, useValue, or useFactory to inject mocks.
class MockDataService { getData() { return of(['mock data']); } } beforeEach(() => { TestBed.configureTestingModule({ providers: [{ provide: DataService, useClass: MockDataService }] }); });
A shared CartService is injected into header and product pages so both see the same cart count.
Angular Angular Tutorial · Angular
Short answer: trackBy is a function used with *ngFor to tell Angular how to track list items uniquely. Why it matters: Without trackBy, Angular recreates DOM elements on each update, causing performance overhead. ✅
<div *ngFor="let item of items; trackBy: trackById"> {{ item.name }} </div> trackById(index: number, item: any) { return item.id; // unique id per item } Angular reuses existing DOM elements instead of recreating them.
ShopNest admin can be built in Angular with modules/components, services for API calls, and reactive forms for product edit.
Angular Angular Tutorial · Angular
Short answer: Lazy loading loads feature modules only when needed (e.g., when a user navigates to a route). Benefits: Reduces initial bundle size → faster app startup. Improves performance and user experience. Enables better code splitting and modularity. Angular supports lazy loading via dynamic route configuration: { path: 'products', loadChildren: () => import('./products/products.module').then(m => m.ProductsModule) }
Angular Angular Tutorial · Angular
Short answer: gainst XSS and CSRF? XSS (Cross-Site Scripting) Protection: Angular automatically sanitizes dangerous content in templates (e.g., {{ userInput }}). Use DomSanitizer for trusted content. Binding syntax prevents direct HTML injection. CSRF (Cross-Site Request Forgery) Protection: Angular’s HttpClient works with backend CSRF tokens. Common… approach: Backend……… sends CSRF token, Angular sends it back via headers or…
cookies. Developers must implement token handling in interceptors.
Angular Angular Tutorial · Angular
Short answer: JWT is a compact, URL-safe token format that securely transmits information between parties. Contains a payload with user info and claims, digitally signed. Angular apps use JWT to: Store authentication state. Send it with API requests to authorize access. Decode JWT to get user roles, expiry, etc.
ShopNest admin can be built in Angular with modules/components, services for API calls, and reactive forms for product edit.
Angular Angular Tutorial · Angular
Short answer: rray. Use useClass, useValue, or useFactory to inject mocks. class MockDataService { getData() { return of(['mock data']); } } beforeEach(() => { TestBed.configureTestingModule({ providers: [{ provide: DataService, useClass: MockDataService }] }); }); rray. Use useClass, useValue, or useFactory to inject mocks.
… class MockDataService {… getData() { return of(['mock data']); } } beforeEach(() => { TestBed.configureTestingModule({ providers: [{ provide: DataService, useClass: MockDataService }] }); }); rray. Use useClass, useValue, or useFactory to inject mocks. Example: class MockDataService { getData() { return of(['mock data']); } } beforeEach(() => { TestBed.configureTestingModule({ providers: [{ provide: DataService, useClass: MockDataService }] }); }); rray. Use useClass, useValue, or useFactory to inject mocks. Example:… class MockDataService { getData() { return of(['mock data']); } } beforeEach(() => { TestBed.configureTestingModule({ providers: [{ provide: DataService, useClass: MockDataService }] }); });
A shared CartService is injected into header and product pages so both see the same cart count.
Angular Angular Tutorial · Angular
Short answer: Comman Purpose ng serve Builds app in memory, runs a dev server, watches files, reloads on changes (for development) ng build Builds app to disk, generates production or development-ready output files
A shared CartService is injected into header and product pages so both see the same cart count.
Angular Angular Tutorial · Angular
Short answer: CommonModule provides common directives like *ngIf, *ngFor, ngClass, etc. You import it in feature modules or any module other than the root module. Don’t import BrowserModule in feature modules; instead, import CommonModule there.
ShopNest admin can be built in Angular with modules/components, services for API calls, and reactive forms for product edit.
Angular Angular Tutorial · Angular
Short answer: ngular reuses existing DOM elements instead of recreating them.
ShopNest admin can be built in Angular with modules/components, services for API calls, and reactive forms for product edit.
Angular Angular Tutorial · Angular
Short answer: Class Role FormContr ol Tracks value and validation status of a single input FormGroup Groups multiple FormControls into a form FormArray Manages an array of FormControls or FormGroups dynamically
Class Role
FormContr ol Tracks value and validation status of a single input FormGroup Groups multiple FormControls into a form
FormArray Manages an array of FormControls or FormGroups dynamically
ShopNest admin can be built in Angular with modules/components, services for API calls, and reactive forms for product edit.
Angular Angular Tutorial · Angular
Short answer: Aspect Constructor ngOnInit Purpose Initializes the class Lifecycle hook, called after constructor Use Case Inject dependencies Fetch data, initialize logic Called By JavaScript engine Angular
constructor(private userService: UserService) {} ngOnInit() { this.userService.getUsers().subscribe(users => this.users = users); } Real-Time Example: In a profile component: Use constructor to inject ProfileService Use ngOnInit to fetch the user's data after initialization
Angular Angular Tutorial · Angular
Short answer: Use Ahead-of-Time (AOT) compilation for faster rendering.
Enable production builds (ng build --prod) with optimizations: Minification Tree shaking Dead code elimination Use lazy loading for feature modules. Bundle analysis: Use tools like source-map-explorer to find large bundles. Use Angular’s built-in caching and service workers (via Angular PWA) for offline and faster repeat loads. Optimize images and assets (compress, lazy load). Use OnPush change detection for components to reduce unnecessary UI updates. Avoid memory leaks by unsubscribing from observables. Use trackBy function with *ngFor to optimize DOM updates.
ShopNest admin can be built in Angular with modules/components, services for API calls, and reactive forms for product edit.
Angular Angular Tutorial · Angular
Short answer: Dependency Injection (DI) is a design pattern in which objects receive their dependencies from an external source, not by creating them. Angular has a built-in DI system that allows services to be injected into components or other services.
constructor(private authService: AuthService) {} Real-Time Example: In an e-commerce app: Inject CartService into CartComponent to manage cart items.
A shared CartService is injected into header and product pages so both see the same cart count.
Angular Angular Tutorial · Angular
Short answer: And faster repeat loads. Optimize images and assets (compress, lazy load). Use OnPush change detection for components to reduce unnecessary UI updates. Avoid memory leaks by unsubscribing from observables. Use trackBy function with *ngFor to optimize DOM updates.
ShopNest admin can be built in Angular with modules/components, services for API calls, and reactive forms for product edit.
Angular Angular Tutorial · Angular
Short answer: CustomEvent is a native JavaScript event that allows sending custom data. In Angular, used in event emitters to pass data from child to parent components. Angular wraps this with @Output() and EventEmitter.
@Output() myEvent = new EventEmitter<string>(); this.myEvent.emit('some data');
ShopNest admin can be built in Angular with modules/components, services for API calls, and reactive forms for product edit.
Angular Angular Tutorial · Angular
Short answer: NgRx is a Redux-inspired state management library for Angular. Uses Actions, Reducers, Store, and Effects to handle application state predictably. Centralizes state for easy debugging, time-travel, and immutability. Ideal for complex apps requiring consistent global state management.
ShopNest admin can be built in Angular with modules/components, services for API calls, and reactive forms for product edit.
Angular Angular Tutorial · Angular
Short answer: TestBed: Core Angular testing utility to configure test modules and components. ngMocks: A library built on top of TestBed to simplify mocking and reduce boilerplate by auto-mocking components, directives, pipes, and services.
A shared CartService is injected into header and product pages so both see the same cart count.
Angular Angular Tutorial · Angular
Short answer: Use the production flag with ng build: ng build --prod This enables: AOT compilation (Ahead-of-Time) Minification and Uglification of code Tree shaking to remove unused code Bundling for fewer HTTP requests Enables optimizations in angular.json
ShopNest admin can be built in Angular with modules/components, services for API calls, and reactive forms for product edit.
Angular Angular Tutorial · Angular
Short answer: BrowserModule includes services essential for running the app in a browser. It also exports CommonModule. Should only be imported once, in the root AppModule. It sets up things like DOM rendering, sanitization, and event handling.
ShopNest admin can be built in Angular with modules/components, services for API calls, and reactive forms for product edit.
Angular Angular Tutorial · Angular
Short answer: ChangeDetectorRef allows you to manually control change detection: detectChanges(): Run change detection immediately. markForCheck(): Mark component to check in next cycle. detach(): Stop change detection for component. reattach(): Resume change detection. ✅
constructor(private cd: ChangeDetectorRef) {} updateData() { this.data = fetchNewData(); this.cd.detectChanges(); // manually trigger update }
ShopNest admin can be built in Angular with modules/components, services for API calls, and reactive forms for product edit.
Angular Angular Tutorial · Angular
Short answer: ngular has a built-in DI system that allows services to be injected into components or other services. constructor(private authService: AuthService) {} Real-Time Example: In an e-commerce app: Inject CartService into CartComponent to manage cart items.
A shared CartService is injected into header and product pages so both see the same cart count.