forkJoin
concatMap
mergeMap
switchMap
forkJoin -> parallel + wait for all to finish.
concatMap → sequential (one after the other).
mergeMap → parallel, but emits results as they arrive.
switchMap → cancels previous when a new one starts.
What is the difference between an attribute directive and a structural directive in Angular?
Attribute directives change the appearance or behavior of an existing element (e.g., changing style or adding classes). Structural directives change the DOM structure by adding or removing elements (e.g., *ngIf, *ngFor).
How can you create a custom attribute directive in Angular?
You create a directive class with the @Directive decorator and use HostBinding/HostListener to manipulate styles or behaviors. Example: highlight a button when it has a custom attribute.
What are the core parts of directives in Angular?
The core parts are: the directive selector, injected dependencies via constructor, and HostBinding/HostListener to interact with DOM elements. Structural directives also use TemplateRef and ViewContainerRef to manage DOM elements dynamically.
Can you show usage of a custom structural directive in Angular?
Yes. Example: *appIf condition, which internally uses TemplateRef and ViewContainerRef to conditionally add or remove elements from the DOM, similar to *ngIf.
What are Angular Modules (NgModules)?
NgModules organize an Angular app into cohesive blocks of functionality. They are defined using @NgModule, which includes metadata such as declarations (components, directives, pipes), imports (other modules), providers (services), and exports (what’s made available outside the module).
What is the main purpose of Angular Modules?
To create reusable, encapsulated groups of code that structure large applications, manage dependencies clearly, and allow easy sharing of functionality across different parts of an app.
What is a directive in Angular?
A directive is a class that can modify the structure or behavior of DOM elements. There are three main types: Components, Attribute Directives, and Structural Directives.
What are the three types of directives in Angular?
What is the difference between attribute directives and structural directives?
Attribute directives change the appearance or behavior of elements (e.g., ngClass, ngStyle). Structural directives change the DOM layout by adding/removing elements (e.g., *ngIf, *ngFor).
How would you implement a custom attribute directive?
You create a directive class decorated with @Directive, inject ElementRef/Renderer2, and apply styles/behavior. Example: highlight button when attribute is applied.
How would you implement a custom structural directive?
You create a directive with @Directive, inject TemplateRef and ViewContainerRef, and use createEmbeddedView() or clear() to manipulate DOM structure.
What are the core building blocks of a directive?
Decorator (@Directive), Selector (CSS-like pattern), and Class with injected dependencies like ElementRef, Renderer2, TemplateRef, or ViewContainerRef.
Can you show usage of a custom structural directive?
Yes. Example: *appUnless works like *ngIf but in reverse. Usage: <div *appUnless=’condition’>Shown if condition is false</div>.
What is ngOnInit used for?
It is a lifecycle hook called after Angular initializes component inputs. It’s used for fetching data, initialization logic, etc.
What is ngOnDestroy used for?
It is a lifecycle hook used for cleanup, unsubscribing from observables, removing event listeners, and freeing resources.
What is ngOnChanges used for?
It runs whenever input-bound properties change. Useful for reacting to @Input updates.
What is an Angular Module?
A logical grouping of Angular classes, components, directives, services, and other modules. Defined with @NgModule decorator.
What are the key metadata fields in @NgModule?
Declarations (components, directives, pipes), Imports (modules to use), Providers (services), and Exports (items made available to other modules).
What is the purpose of declarations in an Angular module?
To declare components, directives, and pipes that belong to this module.
What is the purpose of imports in an Angular module?
To import external modules so their exported classes can be used inside this module.
What is the purpose of providers in an Angular module?
To define services that should be available via dependency injection throughout the module.
What is the purpose of exports in an Angular module?
To make components, directives, or pipes from this module available for use in other modules.
What is the main use case of Angular modules?
To create reusable, cohesive groups of code that can be shared across an application.