Questions tagged [injectable]
121 questions
4
votes
3 answers
"Can't resolve all parameters for service: (?)" when I try to use service from library in Angular 10
In my library I have a service with this code:
import { Inject, Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { DataInjectorModule } from '../../data-injector.module';
// @dynamic
@Injectable()
export…

netdjw
- 5,419
- 21
- 88
- 162
4
votes
1 answer
DowngradeModule and downgradeInjectable result in singleton service per module in Angular/AngularJS hybrid app instead of global singleton
The situation:
I am working on a hybrid project with AngularJS as core where the app slowly needs to be upgraded to Angular 9. So the new Angular modules have to be downgraded to be accessable to AngularJS. The AngularJS app consists of multiple…

BlackFool
- 61
- 4
4
votes
1 answer
Angular 6 testing: How to provide services without their nested dependencies?
I have a ComponentA that uses an ServiceA. I'm writing a test for ComponentA, adding ServiceA into testbed providers. I run the test and get following error:
StaticInjectorError(DynamicTestModule)[ServiceA -> ServiceB]
NullInjectorError: No provider…

Kirill
- 406
- 3
- 11
4
votes
1 answer
Angular 2: how to force an injectable to be a singleton in the app
I have an @Injectable service in my application that is added as a provider in AppModule. I want to make sure no one in my development team injects it in any other module. A single instance is enough and it has some complicated logic that I don't…

eddyP23
- 6,420
- 7
- 49
- 87
4
votes
3 answers
Angular2 - inject into @Injectable
I have an Angular2 app with a service that is used for getting a data from an API. Following this example, I want to create a separate file which should contain some configuration data. My problem is that my service has an @Injectable() decorator…

Radoslav Stoyanov
- 1,460
- 5
- 27
- 40
4
votes
1 answer
ViewHelper newable/injectable dilemma
I'm trying to design an application following Misko Heverys insights. It's an interesting experiment and a challenge. Currently I'm struggling with my ViewHelper implementation.
The ViewHelper decouples the model from the view. In my implementation…

koen
- 13,349
- 10
- 46
- 51
3
votes
1 answer
How to register a class with generic type param using injectable?
I have a bloc, that I want to register for DI:
@injectable
class ViewBloc extends Bloc { }
As you can see the ViewBloc takes a generic type param T. The problem is that when the injectable register the dependency, it's…

Nebex Elias
- 252
- 1
- 3
- 14
3
votes
1 answer
Flutter dependency injenction with shared preferences
Good evening,
I'm trying to use dependency injection with the shared preferences plugin, but as soon is I generate the code, I get an error for an unrelated Bloc.
I use
GetIt: ^0.5.3,
injectable_generator: 1.0.6
flutter_bloc: ^6.1.1.
My Goal is to…

niclassic
- 117
- 2
- 7
3
votes
1 answer
In nestjs how DI will work if Injectable is not mentioned in service but the service is registered as a provider in every module
What will happen if I declare a service as provider in a module but did not use @Injectable decorator in the service?
//Module
module({
controller: [catController],
provider: [catService]
})
//Service
//@Injectable()
export class…

markadm
- 83
- 3
3
votes
1 answer
[Angular 7+]: How to unit test a service inside another service spec?
I have these two service files where one is included in another.
app.service.ts
import { Injectable } from '@angular/core';
import { HttpClient, HttpHeaders } from '@angular/common/http';
import { throwError, Observable } from 'rxjs';
…

Neeraj
- 483
- 9
- 17
3
votes
1 answer
Can't resolve all parameters for LoggedinPage (Angular - Component/Injectable)
I getting this error when running my ionic app:
Can't resolve all parameters for LoggedinPage: (?, [object Object], [object Object]).
When calling AuthService (of type Injectable) in the constructor.
The weird part is that its working perfectly…

JamesAnd
- 410
- 1
- 8
- 28
3
votes
1 answer
what is diff in @Injectable() and @Inject
I am working on angular2 I have created service and inject those service using @Inject in component. I am confuse with the use of @Injectable() in service itself and what diff it makes.

Rhushikesh
- 3,630
- 8
- 45
- 82
3
votes
2 answers
Problems with NavController when unit testing an Ionic 2 app
I'm having trouble unit testing with NavController.
I'm stuck at this error:
Cannot resolve all parameters for 'NavController'(?, ?, ?, ?, ?, ?, ?, ?). Make sure that all the parameters are decorated with Inject or have valid type annotations and…
3
votes
1 answer
Missing invocation to mocked type at this point;
I am new to jMockit. I am trying to mock multiple instances of java.io.File type in a method. There are some places where, I shouldn't mock file Object. For that reason, I am using @Injectable. It is throwing the below exception.
I don't want to…

krishth
- 83
- 1
- 1
- 9
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…

F-H
- 663
- 1
- 10
- 21