Angular Concepts Review - DI, Routing, Forms, RxJS, TypeScript, Web/REST

0.0(0)
studied byStudied by 0 people
GameKnowt Play
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
Card Sorting

1/108

flashcard set

Earn XP

Description and Tags

A set of practice flashcards covering key Angular concepts including DI, modules, routing, forms, RxJS, TypeScript, and REST/WebSocket topics.

Study Analytics
Name
Mastery
Learn
Test
Matching
Spaced

No study sessions yet.

109 Terms

1
New cards

What is Dependency Injection in Angular?

A design pattern where a class receives its dependencies from external sources rather than creating them itself. By using @Injectable({ providedIn: 'root' }) or adding it to a module/component providers array. 'root' creates a singleton service across the app; component providers create a new instance for that component's scope.

2
New cards

How do you provide a service in Angular?

By using @Injectable({ providedIn: 'root' }) or by listing the service in a module or component's providers array.

3
New cards

Difference between providedIn: 'root' and component providers?

'root' makes the service a singleton shared across the app; component providers create a new instance scoped to that component and its children.

4
New cards

Purpose of @Injectable() in Angular?

Marks a class as injectable and allows Angular to inject dependencies into it.

5
New cards

What is an injector tree?

A hierarchy of injectors in Angular used to resolve dependencies starting from the closest injector upward.

6
New cards

Can services have dependencies themselves?

Yes, services can have dependencies injected via their constructor, which Angular resolves recursively.

7
New cards

What is useClass in DI?

Tells Angular to provide a different class when a dependency is requested.

8
New cards

What is useValue in DI?

Tells Angular to inject a fixed value instead of creating an instance.

9
New cards

What is useFactory in DI?

Allows you to provide a dependency using a factory function for dynamic creation.

10
New cards

What is useExisting in DI?

Creates an alias to use an existing provider rather than creating a new instance.

11
New cards

What are Angular modules?

Containers for a group of components, directives, pipes, and services.

12
New cards

What is a component in Angular?

A building block of Angular applications controlling a view via HTML, CSS, and TypeScript.

13
New cards

Purpose of NgModule decorator?

Defines metadata for an Angular module, including declarations, imports, exports, and providers.

14
New cards

What is a directive in Angular?

A class that adds behavior to elements in Angular templates.

15
New cards

What is a pipe in Angular?

A class for transforming displayed values in templates.

16
New cards

What is the difference between pure and impure pipes?

Pure pipes execute only when inputs change; impure pipes run every change detection cycle.

17
New cards

What are Angular lifecycle hooks?

Special methods like ngOnInit, ngOnChanges, ngOnDestroy used at specific component lifecycle stages.

18
New cards

What is Ahead-of-Time (AOT) compilation?

Compiling Angular templates at build time for faster rendering.

19
New cards

What is ViewEncapsulation?

Defines how CSS styles are scoped to components.

20
New cards

What are Angular zones?

Execution contexts that help Angular detect and react to asynchronous operations.

21
New cards

What is the Angular Router?

A module that enables navigation between views in a single-page application.

22
New cards

How to define a route in Angular?

By adding an object with path and component to the RouterModule.forRoot() or forChild().

23
New cards

What is a wildcard route?

A route with path '**' that matches any undefined paths.

24
New cards

How to create route parameters?

By defining a route path with :paramName and accessing it via ActivatedRoute.

25
New cards

What is lazy loading in Angular routing?

Loading feature modules only when their route is accessed.

26
New cards

What is a resolver in Angular routing?

A service that fetches data before activating a route.

27
New cards

How to navigate programmatically in Angular?

By injecting Router and calling router.navigate().

28
New cards

What is routerLinkActive?

A directive that adds a CSS class to an element when the linked route is active.

29
New cards

Difference between forRoot and forChild in RouterModule?

forRoot configures the main application routes; forChild configures feature module routes.

30
New cards

How to protect routes in Angular?

By using route guards like CanActivate, CanDeactivate, etc.

31
New cards

What is an Angular Guard?

A service that controls navigation based on logic, e.g., AuthGuard.

32
New cards

What is CanActivate?

A guard that decides if a route can be activated.

33
New cards

What is CanDeactivate?

A guard that decides if a route can be exited.

34
New cards

What is Resolve in routing?

A guard that pre-fetches data before a route activates.

35
New cards

What is an HTTP interceptor?

A service that intercepts HTTP requests/responses to modify or handle them globally.

36
New cards

How to implement an HTTP interceptor?

By creating a class implementing HttpInterceptor and adding it to HTTP_INTERCEPTORS providers.

37
New cards

Use cases for HTTP interceptors?

Adding authentication tokens, logging, error handling.

38
New cards

Difference between intercepting request and response?

Requests are modified before being sent; responses after being received.

39
New cards

Can interceptors be chained?

Yes, multiple interceptors run in the order they're provided.

40
New cards

How to skip an interceptor for specific requests?

By checking request URL or adding custom headers and conditionally skipping logic.

41
New cards

Difference between template-driven and reactive forms?

Template-driven forms rely on Angular directives; reactive forms use explicit form control objects.

42
New cards

What is FormControl?

A class that tracks the value and validation status of an individual form input.

43
New cards

What is FormGroup?

A group of FormControls that can be validated together.

44
New cards

What is FormBuilder?

A service that simplifies creating FormControl and FormGroup instances.

45
New cards

What are form validators?

Functions that check form control values for validity.

46
New cards

What is async validator?

A validator function that returns a Promise or Observable.

47
New cards

How to display form validation errors?

By checking control.errors and conditionally rendering messages.

48
New cards

What is patchValue vs setValue?

setValue requires all controls; patchValue updates only specified controls.

49
New cards

What is valueChanges in forms?

An Observable that emits whenever the form control's value changes.

50
New cards

What is statusChanges in forms?

An Observable that emits whenever the validation status changes.

51
New cards

What is an Observable in Angular?

An asynchronous data stream that can emit multiple values over time.

52
New cards

What is a Subject in RxJS?

An Observable that can multicast to multiple observers.

53
New cards

Difference between Subject and BehaviorSubject?

BehaviorSubject has an initial value and emits the last value to new subscribers.

54
New cards

What is a ReplaySubject?

An Observable that emits a specified number of previous values to new subscribers.

55
New cards

What is an AsyncSubject?

It emits only the last value upon completion.

56
New cards

What is an operator in RxJS?

A function that enables functional programming with Observables.

57
New cards

Difference between map and switchMap?

map transforms values; switchMap switches to a new Observable cancelling the previous one.

58
New cards

What is mergeMap?

Maps each value to an Observable and merges the results.

59
New cards

What is concatMap?

Maps values to Observables and subscribes to each sequentially.

60
New cards

What is exhaustMap?

Ignores new emissions until the current Observable completes.

61
New cards

Difference between interface and type in TypeScript?

Interfaces define contracts for objects; types can define unions, primitives, and complex types.

62
New cards

What are generics in TypeScript?

A way to create reusable code components that work with different types.

63
New cards

What is type inference?

The compiler automatically infers the type based on the value.

64
New cards

What is type assertion?

A way to tell the compiler to treat a value as a specific type.

65
New cards

Difference between unknown and any?

unknown is safer; it requires type checks before use.

66
New cards

What are enums in TypeScript?

A way to define named constants, numeric or string.

67
New cards

What is a union type?

A type that can be one of several types.

68
New cards

What is an intersection type?

A type that combines multiple types into one.

69
New cards

What is the difference between private, protected, and public?

Access modifiers that control visibility of class members.

70
New cards

What is a namespace in TypeScript?

A way to organize code into logical groups and avoid naming conflicts.

71
New cards

What is a closure in JavaScript?

A function that remembers the variables from its lexical scope even when executed outside that scope.

72
New cards

What is 'this' in JavaScript?

A keyword referring to the object that is currently executing the function.

73
New cards

What are arrow functions?

Functions with a concise syntax that do not have their own 'this'.

74
New cards

Difference between var, let, and const?

var is function-scoped; let and const are block-scoped; const cannot be reassigned.

75
New cards

What is hoisting in JavaScript?

The process where variable and function declarations are moved to the top of their scope.

76
New cards

What is event delegation?

Attaching an event listener to a parent to handle events from its children.

77
New cards

What are promises in JavaScript?

Objects representing eventual completion or failure of an asynchronous operation.

78
New cards

What is async/await?

Syntax for working with promises in a synchronous-like manner.

79
New cards

What is the spread operator?

A syntax to expand elements of an array/object.

80
New cards

What is destructuring?

A syntax for unpacking values from arrays or properties from objects.

81
New cards

What is Change Detection in Angular?

The process Angular uses to check and update the DOM when data changes.

82
New cards

Difference between default and OnPush change detection?

Default runs often; OnPush runs only when inputs change or events occur.

83
New cards

What is a custom structural directive?

A directive that changes the DOM layout, e.g., *ngIf.

84
New cards

How to optimize Angular performance?

Using OnPush, trackBy in ngFor, lazy loading, and avoiding unnecessary change detection.

85
New cards

What is trackBy in ngFor?

A function that helps Angular track items by a unique identifier to improve performance.

86
New cards

What is Angular Universal?

Server-side rendering for Angular apps.

87
New cards

What are service workers in Angular?

Scripts that enable offline support and caching for PWA functionality.

88
New cards

What is Ivy in Angular?

The default rendering engine introduced in Angular 9.

89
New cards

What is ViewChild in Angular?

A decorator to access a child component, directive, or DOM element.

90
New cards

What is ContentChild in Angular?

A decorator to access projected content inside a component.

91
New cards

What is the difference between Renderer2 and direct DOM manipulation?

Renderer2 is Angular's safe way to manipulate DOM, ensuring compatibility with different environments.

92
New cards

What is a template reference variable?

A variable in a template that refers to a DOM element or directive instance.

93
New cards

What is ngZone in Angular?

A service to run code inside or outside Angular's change detection.

94
New cards

What are dynamic components in Angular?

Components created and loaded at runtime using ComponentFactoryResolver or ViewContainerRef.

95
New cards

What is differential loading in Angular?

A way to load different bundles for modern and legacy browsers.

96
New cards

What is internationalization (i18n) in Angular?

The process of making the app adaptable to different languages and locales.

97
New cards

What is a singleton service?

A service that has only one instance throughout the application.

98
New cards

What is a multi-provider in Angular DI?

A provider configuration that allows multiple values for the same token.

99
New cards

What are tokens in Angular DI?

Identifiers used to locate dependencies in the injector.

100
New cards

What is platformBrowserDynamic in Angular?

A function that bootstraps an Angular app in the browser at runtime.