145 questions
0
votes
1
answer
123
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 ...
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
2
answers
268
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
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
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 ...
2
votes
1
answer
122
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 ...
2
votes
1
answer
629
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,
}
...
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 ...
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, ...
1
vote
2
answers
619
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
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
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 ...
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 ...
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,...
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 ...
0
votes
1
answer
100
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 ...
0
votes
3
answers
111
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
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 ...
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 } ...
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]=...
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....
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
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, ...
1
vote
0
answers
133
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
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 ...