Questions tagged [angular-injector]

28 questions
4
votes
2 answers

How to dynamically inject a service from a lazy loaded module in Angular 9+ without components?

I am attempting to access an instance of a service from a lazy loaded module from within a component. The module does not have any components to use for constructor-based injection. The Angular documentation was not helpful and all the various…
Jason K.
  • 790
  • 1
  • 14
  • 22
4
votes
2 answers

Create is deprecated: from v5 use the new signature Injector.create(options) (deprecation)

I Have a TabService that Inject Tabs Into mat-tab-groups, In Constructor I Inject Instance of Injector from @angular/core constructor( private loader: NgModuleFactoryLoader, private injector: Injector ) {} Then I use create method to…
Masoud Bimmar
  • 6,941
  • 4
  • 30
  • 33
2
votes
0 answers

How can I register my own injection providers globally to work around circular module dependencies?

We can use Angular's @Injectable decorator to make a service available for dependency injection throughout the application. In this case, the service class itself will be used as the injection token; whoever injects it must know the class. We can…
2
votes
1 answer

What is @SkipSelf decorator in Angular?

The @SkipSelf decorator tells DI to look for a dependency in the whole tree starting from the parent injector I came across the @SkipSelf decorator as below. What does this @SkipSelfdecorator exactly mean in this case? class Dependency…
1
vote
0 answers

NgxsModule.forRoot([]) in child module (instead of app.module.ts)

I am trying to use Ngxs only in one of my components in application. When I import NgxsModule.forRoot([]) in my child module where I will be using it I'm getting this error and whole application is not working: Error: Uncaught (in promise):…
joanna
  • 11
  • 2
1
vote
1 answer

NullInjectorError: No provider for service in library

Problem: I work in angular workspace and I import common.module.ts from library (library generated with ng generate library) to my app.module.ts, but when I inject CommonService in app.component.ts I get error: main.ts:11 ERROR NullInjectorError:…
1
vote
1 answer

Angular material not working in an angular library

I have some angular projects and I have seen that there is a lot of code that can be reusable, so I thought on making some of the code part of a common library. I created the library following the steps in the…
1
vote
1 answer

Why does Angular injector detect the following provided even if its not in the injector heirarchy?

From the official docs, following is an example of lightweight injection token pattern for enabling tree shaking: abstract class LibHeaderToken {} @Component({ selector: 'lib-header', providers: [ {provide: LibHeaderToken, useExisting:…
Daud
  • 7,429
  • 18
  • 68
  • 115
1
vote
2 answers

Angular Service inject parameter in constructor based on component @Input property

I have a Service with a parameter in the constructor here a simple string later on a url or other objects. This parameter is a set for the internal behaviour of the service, here just instantiate different values. constructor(@Inject(AUTHOR_TYPE)…
G.D.
  • 75
  • 9
1
vote
2 answers

Angular restrict service to only one component tree

i want to implement a service and let it provide to only one named component or module and not to any other component or module. So whenever anyone tries to provide that service to another component they get an error and the program should not…
Vipin Jain
  • 1,382
  • 1
  • 10
  • 19
0
votes
1 answer

config.json and using values in app.module.ts providers

Currently, we are building our angular (v15) application once for each environment we deploy to, since we are using the environment.ts files to handle variable transforms. I would like to get us to a flow more similar to our backend, AspNetcore,…
Delubear
  • 56
  • 5
0
votes
1 answer

injecting a variable into my library service

I'm creating a library in angular, which uses HttpClient and I need to inject the baseUrl to use. this is what I have in the library: //service export class ApiService { constructor( private readonly httpClient: HttpClient, @Inject('baseUrl')…
cucuru
  • 3,456
  • 8
  • 40
  • 74
0
votes
1 answer

Angular - InjectionToken with Parameter

I have an InjectionToken like: export const SOURCE_DATA_INJECTION_TOKEN = new InjectionToken('All Source Data', { providedIn: 'root', factory: () => { // Returns all source return someArrayData // This…
itsji10dra
  • 4,603
  • 3
  • 39
  • 59
0
votes
1 answer

Testing @inject parent and @contentChildren together

I am developing a custom tab component composed by a parent and children like this: Parent @Component({ selector: 'app-custom-tabs', template: `
Carla C
  • 79
  • 5
0
votes
1 answer

Injecting translate pipe to NgRx Effect and it throws NullInjectorError

I'm Injecting translate pipe to NgRx Effect and it throws NullInjectorError even though the pipe is provided in the module that holds the effect. the package that I'm using for the translation is @ngx-translate/core. Note: I was able to use the…
Or Shalmayev
  • 295
  • 1
  • 12
1
2