Questions tagged [angular-di]

34 questions
2
votes
1 answer

Angular: How to get component dependancy via console?

I put focus on component element in dev tools and can do following: ng.probe($0) to get the special object "DebugElement". Now we can get its injector: ng.probe($0).injector now I would like to get a dependancy that is defined on this component.…
Stepan Suvorov
  • 25,118
  • 26
  • 108
  • 176
1
vote
2 answers

Lazy loading messes up DI on angular

I have a module A that is a npm package that I need to use on module B that is also an npm package that is used on an app. Module B is lazy loaded by the app. So I have the following service on module A: @Injectable({ providedIn:…
1
vote
1 answer

How to pass dynamic variable to http_interceptor from a service

I have multiple angular projects and each project has a service to call the same API. I've been adding a header to request to determine from which app the request has been sent. So I've been trying to create a library having a base service class to…
VTO
  • 13
  • 4
1
vote
1 answer

how to provide another control value accessor?

I've already got a directive what is implementing the ControlValueAccessor interface (directive's selector is input[type=date]) and I need to have another directive implementing ControlValueAccessor with selector input[type=date][datepicker] - let's…
roomcayz
  • 2,334
  • 4
  • 17
  • 26
1
vote
0 answers

Where does the Angular DI useFactory() context come from?

With angular (per this article) useFactory() can be used to add decision making on what to provide the component with during DI. Here's an example from the article: useFactory: ()=> { if( ... ) return firstObject ... } My question is where does…
Ole
  • 41,793
  • 59
  • 191
  • 359
1
vote
1 answer

Why markForCheck() works only for one branch?

It's clear that we need to use markForCheck() mostly with OnPush strategy to mark component to do the CD check, but I'm trying to figure out why to check only one branch: Why could run CD for whole app or only specific component, no?
Stepan Suvorov
  • 25,118
  • 26
  • 108
  • 176
0
votes
1 answer

Can I re-provide a service for nested modal dialog component without overriding existing same token provided service?

If I inject a service 'Z' to component 'A' which spawns a dialog component 'B' which requires the service 'Z' to be a newly fresh copy of the service (provided in 'B' again). Will closing dialog 'B' "release" that nested service 'Z' so that…
0
votes
1 answer

How to inject the right service depending on the context of UI?

I have a component that renders a list of users (it injects its related service called UserService) in a dedicated module I have another component that renders a list of Products (inject its related service called ProductService) in a dedicated…
0
votes
1 answer

Angular: dependency injection not happening properly if we place .js or .ts at the end of import statement

A typical import statement goes like this: import {HelpService} from '../../help.service' If I autowire HelpService in the constructor, I get an existing instance of HelpService. However, if I import it like this: import {HelpService} from…
Daud
  • 7,429
  • 18
  • 68
  • 115
0
votes
1 answer

Injecting Angular service in custom Angular validator

I have created a custom validator in Angular. I am using an Angular service in the validator validateFund function.However, Angular is providing a new instance of the service; my validation always fails when I try to validate the data since the…
0
votes
0 answers

Providing services dynamically in Angular

I have a DI problem I am trying to resolve without bloating my code: The setup is as follows: I have a base form class 'A' that communicates with some of its child components employing service 'B'. Class 'A' has many (say 50) inheriting form…
rubmz
  • 1,947
  • 5
  • 27
  • 49
0
votes
0 answers

How to inject service instance into feature module in angular

I want to inject a service created one module into a second totally different module, that depends on some data created by the first module. Let's say you import a feature module for authentication into your project and also a module to create a…
andreas.teich
  • 789
  • 1
  • 12
  • 22
0
votes
1 answer

How to add http interceptor only in one specific NgModule (without lazy-loading)?

I need to implement some feature. I want to provide some http interceptor in modules A and B. I want each http request from module A to be sent with some header like 'zone: a-feature'. Any request from module B must be sent with header like 'zone:…
Sharikov Vladislav
  • 7,049
  • 9
  • 50
  • 87
0
votes
1 answer

Angular DI - useFactory - Provider : Is there a way to invoke Provider Factory function second time when local State gets updated?

The scenario goes as follows: 1. App has root module and it's constructor resolves a Promise and returns a Constant. @NgModule({ ...., providers : [ ... { provide: SAMPLE_INJECTOR_TOKEN, useFactory:…
0
votes
0 answers

What is the correct way of getting reference to Parent Angular Component?

I try to get in the child component reference to its parent Angular component based on components tree. What is the correct way to do this? I have found out that injector.view is actually the reference I am looking for but this API is not…
Hivaga
  • 3,738
  • 4
  • 23
  • 36