145 questions
0
votes
1
answer
120
views
Angular 19 ApplicationConfig use Configuration in factory
In GitOp I want to replace config.json for each environment and with this internal app I want to keep it as simple as possible (e.g. no ngrx)
My problem is that config.json is loaded in a ...
0
votes
1
answer
146
views
How to pass a default value with @Optional in Angular 20?
In Angular 20, how can we inject an optional InjectionToken with a default value?
In Angular <20, I used to do it as follows:
constructor(@Optional@Inject(FOO) private foo = true){}
1
vote
2
answers
2k
views
How to use new Angular 20 inject syntax with
I'm using @Inject(String) to enable giving config at the instantiation of my service.
Here's the code:
const httpLoaderFactory: (http: HttpClient) => TranslateHttpLoader = (http: HttpClient) =>
...
0
votes
0
answers
17
views
How could mimic the module experience with Angular standalone components?
Since it looks like the modules in Angular are near the end of their life, and stand-alone components are the future, how can we provide dependencies in the same way as when a module is used?
With ...
0
votes
2
answers
263
views
How can I inject an Angular service into a custom class?
I have this custom class called SortState that represents sorting and paging on a table of records. Now I want to make that class talk to a service that displays a loading indicator. Apparently you ...
1
vote
1
answer
117
views
Angular Firebase Error: "NullInjectorError: No provider for Firestore2!" in Standalone Component
I'm working on an Angular standalone component using Firebase, and I'm encountering the following error:
ERROR NullInjectorError: R3InjectorError(Standalone[_AppComponent])[_FirebaseService -> ...
1
vote
1
answer
53
views
Functional style interceptors - How to provide them with dependencies
Imagine the situation where you provide any lib to client. Simple scenario, spinner interceptor which needs spinner service.
In old way it was possible to:
providers: [
{
provide: ...
1
vote
2
answers
344
views
Angular standalone:chain multiple functions in provideAppInitializer
In my Angular application (version 19), I have a provideAppInitializer like this:
export const appConfig: ApplicationConfig = {
providers: [
...
provideAppInitializer(intializeAppFn),
...
1
vote
1
answer
109
views
Error NG2003: No suitable injection token for parameter 'exportAsService' – ngx-export-as issue in Angular component reuse [closed]
I'm working on an Angular project and using the ngx-export-as package, which was already installed and working fine in some of my components.
However, when I tried to use the same ExportAsService in a ...
1
vote
1
answer
55
views
Restructuring a super call in a constructor to use the 'this'
I have the following service:
import {
ENVIRONMENT_TOKEN
} from '@reg/environment/domain'
@Injectable({ providedIn: 'root' })
export class RegStore extends ImmutableStore<TRegState> {
#env =...
2
votes
1
answer
121
views
How to provide a HostAttributeToken in Angular tests?
I recently discovered the HostAttributeToken in Angular (see docs) to provide static attributes for a component.
The following example works fine:
import { Component, HostAttributeToken, inject } from ...
0
votes
1
answer
150
views
NullInjectorError: R3InjectorError
I'm working in a personal project, using angular, but I receive the following error all the time:
NullInjectorError: R3InjectorError(Environment Injector)[_HttpClient->_HttpClient]: ...
2
votes
1
answer
628
views
convert APP_INITIALIZER code to newer provideAppInitializer syntax
I have a piece of code from an angular application like below,
{
provide: APP_INITIALIZER,
deps: [...config.mockApi.services],
useFactory: () => (): any => null,
multi: true,
}
...
5
votes
2
answers
6k
views
Angular 19 Standalone Component Error: "No provider for _HttpClient" Despite HttpClientModule Imported
I am working on an Angular standalone application and encountering the following error when using HttpClient in my DataService:
ERROR Error [NullInjectorError]: R3InjectorError(Standalone[...
1
vote
1
answer
75
views
Angular DI for standalone components with importing module on parent component and child component (NullInjectorError: R3InjectorError)
Given the following structure:
a parent standalone component named AppComponent
a child standalone component called TableComponent, which should be a wrapper for a generic table
TableComponent ...
2
votes
1
answer
159
views
Troubleshooting NG0203 Error: Issues with Angular Library and HttpClient Injection in Production Build
I wasn't able to solve it. I'm counting on your help.
I have an Angular application and a library.
In the library, I have a service where I inject HttpClient. I set HttpClient as a provider in the ...
6
votes
2
answers
2k
views
How to access provider value in Angular 19
Using Angular SSR, I would like to access a server-side value in my app.component.
Here is my server-side route:
app.get('**', (req, res, next) => {
const { protocol, originalUrl, baseUrl, ...
3
votes
2
answers
210
views
Can we remove all the constructor-based injections?
Recently, Angular put in place a migration to replace constructor-based injection with inject function.
In most of the cases, it is straightforward and it clearly has benefits:
// before
@Injectable({ ...
1
vote
2
answers
617
views
How to inject a Service inside ApplicationConfig?
How to inject a Service inside ApplicationConfig?
export const appConfig: ApplicationConfig = {
providers: [
provideRouter(appRoutes),
provideTransloco({
config: {
...
1
vote
0
answers
73
views
Using Injector.create() to dynamically create injector for embedded view is not working when parent injector is provided via parent property
I want to dynamically create the injector for embeddedView and for that purpose I use Injector.create() method:
const myInjector = Injector.create({
providers: [
{
...
1
vote
1
answer
52
views
Injecting a service in Angular using a Symbol does not work in Firefox
My Angular app works in Chrome.
export interface UserService {
me(): Observable<Response<User>>;
}
export const UserServiceRef = Symbol();
----
providers: [
{
provide: ...
0
votes
2
answers
295
views
Angular 18 Multiple instance of same service
I've:
service DataLoader who read/write data in DB.
service Report who instances DataLoader using inject
standalone component who inject DataLoader and Report too.
At this point, only one instance of ...
0
votes
0
answers
76
views
Why Angular provider is not detectedin standalone component?
I have a component, which I will build using my custom builder. This builder builds my component in ESM format.
My component code (which will be built) is a simple standalone component which imports ...
4
votes
1
answer
5k
views
Angular Standalone - How to Inject Service into Service
I'm a longtime Angular dev now trying to learn the standalone version. How do I inject a service into another service without a providers array in the NgModule. Is my only choice using providedIn in ...
0
votes
1
answer
121
views
Angular component with content projection causes incorrect service injection
I have an Angular directive (LevelDirective) designed to determine its level based on its parent's level (i.e. if parent has level 1 => I should have level 2). It uses a standalone LevelService to ...
1
vote
1
answer
95
views
Angular Service State Not Updating for Subscribers Even After Using BehaviorSubject
I'm working on an Angular service that fetches rules from a secondary cart and updates a BehaviorSubject to manage the state. However, my subscribers are not receiving updates even after the state is ...
2
votes
1
answer
1k
views
DOCUMENT injection token for SSR angular service causes NotYetImplemented error
I have an Angular SSR app with a service that references document. I use the DOCUMENT injection token to provide document as a DI. Here is the repo: https://github.com/JakeLo123/ng-ssr
import { Inject,...
2
votes
1
answer
507
views
Injecting document into angular service for SSR
I am creating an angular library that has a root-level service class that references document. I'd like to add SSR support, but of course document is not defined in SSR context. It seems that Angular ...
0
votes
1
answer
62
views
Which type of injector injects the ViewContainerRef or ElementRef?
I read several articles about the two types of injector hierarchies in Angular - the ElementInjector and the EnvironmentInjector hierarchies, and what type of dependencies they provide, and how when ...
1
vote
1
answer
210
views
How do viewProviders and @Host work together in Angular?
Given the following example on stackblitz
@Injectable()
export class LogService {
sayHello() {
console.log('Hello World !');
}
}
@Component({
selector: 'app-child',
standalone: true,
...
0
votes
1
answer
99
views
Who has the responsibility to instantiate "background" services in Angular?
I'm following the Angular documentation for service workers (https://angular.io/guide/service-worker-communications). The page lists a series of examples of services used to handle service worker ...
1
vote
1
answer
1k
views
Combine route resolver provider and component provider in Angular
I want to 'attach' a signal store to one of my components. I intend to provide this at component level and not at the root, as the state is specific to that component.
However I like to use route ...
0
votes
3
answers
110
views
Creating custom Router class in Angular leads to exception
I want to override the function navigate(commands: any[], extras?: NavigationExtras): Promise<boolean> of Router to always set queryParamsHandling to true in the NavigationExtras.
Therefore I ...
1
vote
0
answers
596
views
Angular NullInjectorError under module-federation remoteEntry.js injecting an abstract service to another service across two Angular projects
I am getting a NullInjectorError error when I use an Angular component in a federated module (via remoteEntry.js), while it is working well in a standalone Angualar app.
It is (and has to be) a ...
1
vote
1
answer
663
views
Making sure my Angular library's service is constructed offering standalone friendly provide function
I am authoring an Angular library. It contains a service, which runs initialization logic in the constructor that is required for the library to work properly. I have set up the library module with a ...
1
vote
1
answer
1k
views
Angular Material dialog not receiving MAT_DIALOG_DATA when created from canActivate
I'm trying to read a query param on a given route in the canActivate function and if it's not there, show a modal saying that it's not going to work ok.
When I think more about this, because it's only ...
0
votes
0
answers
392
views
Error: NG0200: Circular dependency in DI detected
Injecting a different service in an interceptor is giving the above mentioned error even though Iam not importing httpClient into the the service.
logger.interceptor.ts
import { HttpInterceptorFn } ...
3
votes
2
answers
11k
views
angular - ERROR NullInjectorError: No provider for
I'm trying to list all the categories from my asp .net application, and im receiving this nullinjector error:
ERROR NullInjectorError: R3InjectorError(_AppModule)[CategoriaServiceList -> ...
1
vote
0
answers
95
views
Angular: ng-content and token provision - how to make projected content find the inner templates' tokens instead the outer DOMs one?
I have a BadgeComponent with this template:
<draw-circle
[position.x]="position.x"
[position.y]="position.y"
[resolution]="20"
[radius]="2"
[color]=...
1
vote
0
answers
44
views
isolated angular service instance within an ngModule
I have a scenario where I want to share a service within a NgModule. but at the same time I want to keep its instances usage separate.
stackblitz
in the stackblitz, you can see that I have a hover-...
7
votes
4
answers
31k
views
How to inject application config into app module in angular
I am using Angular v16 and I have the following config that needs to be included in app.module. What is the best way to inject appConfig in app.module? It works if I include them directly inside app....
2
votes
0
answers
65
views
How do I transfer generically typed data using dependency injection?
My application displays data about different kinds of business objects in the same standard component.
That is, let's assume there is an Angular component type EditorComponent<T extends object>.
...
1
vote
0
answers
205
views
How does Angular distinguish/match injection tokens?
tl;dr: How does Angular know that an injection token passed to injector.get corresponds with an injection token of a particular provider?
According to the Angular documentation, an InjectionToken can ...
0
votes
1
answer
1k
views
How to inject the NGRX store in a functional angular resolver
I'm trying to convert my class-based resolver to a functional one. Injecting NGRX store is not working.
export const loadCategoriesParentCategoryCodeResolver
: ResolveFn<boolean> = (
route,
...
0
votes
1
answer
301
views
Inject components with a directive into a referenced element (Angular 12)
Now I inject my extra components to my main component's root level in a directive, with this approach:
@Directive({
selector: '[my-controls]',
})
export class MyControlsDirective implements OnInit, ...
7
votes
1
answer
3k
views
What is the injection context in Angular 16+
Im faced with a term called "Injection context", and trying to figuring out what it actually is.
Coz in angular we have following things that somehow related with injection context (listed ...
1
vote
0
answers
131
views
How to share NgxPermissionsService instances across AppModule, Feature Module and a Library Module
I'm trying to use ngx-permissions to manage my app permissions.
My app is depending on a library to share some features to different apps and the permissions will be loaded by this library.
The ...
0
votes
1
answer
116
views
Angular optional multi interceptors - why is it injected as null?
Given a multi injectable defined like below, without any providers, I would expect the injected list to be empty, but in reality it is null.
Is there a way to inject the value as [] instead of null if ...
0
votes
0
answers
53
views
Angular Same Service Instance in different Modules
so i have started to learn more about Dependency Injection. And as it was written in Docs, i expect that if i have 2 separate modules and both of them have their own provider in provider array. I'll ...
0
votes
2
answers
126
views
Angular - choose class to inject based on URL / logic available at bootstrap
(How) is it possible to configure injectors to use a class based on some data available at bootstrap?
I have two implementations for interfacing with the backend, (for simplicity, let's say over http ...