Questions tagged [angular-providers]

The service providers are constructor functions. When instantiated they must contain a property called $get, which holds the service factory function.

angularjs doc

173 questions
71
votes
6 answers

How override Provider in Angular 5 for only one test?

In one of my unit test files, I have to mock several times the same service with different mocks. import { MyService } from '../services/myservice.service'; import { MockMyService1 } from '../mocks/mockmyservice1'; import { MockMyService2 } from…
hbaltz
  • 711
  • 1
  • 5
  • 4
33
votes
9 answers

Possibly unhandled rejection in Angular 1.6

I have a code with AngularJS: service.doSomething() .then(function(result) { //do something with the result }); In AngularJS 1.5.9 when I have error in the .then() section like: service.doSomething() .then(function(result) { var x…
22
votes
3 answers

Angular Async Factory Provider

I would like to set up a factory that does async work to return a service, and then provide that factory to a factory provider to provide that service to a component when it loads. However, when the provider injects the TestService into the…
Sharpiro
  • 2,305
  • 2
  • 18
  • 27
13
votes
4 answers

Angular: Metadata collected contains an error that will be reported at runtime: Lambda not supported

In my Angular app, I'm trying to use a factory provider in my module: export function getMyFactory(): () => Window { return () => window; } @NgModule({ providers: [ { provide: WindowRef, useFactory: getMyFactory() }, ], }) export class…
12
votes
1 answer

What does multi:true mean in providers in angular4

I am using HTTP_INTERCEPTORS in angular4. For this, I have created HttpServiceInterceptor class that implements HttpInterceptor interface and provide the defintion for intercept method. Then registered provider for HTTP_INTERCEPTORS like…
Sunil Garg
  • 14,608
  • 25
  • 132
  • 189
9
votes
2 answers

Why does this test for the angular-google-maps provider fail?

I'm trying to test a module that uses angular-google-maps. It is failing because angular.mock.inject cannot find uiGmapGoogleMapApiProvider: Error: [$injector:unpr] Unknown provider: uiGmapGoogleMapApiProviderProvider <-…
7
votes
0 answers

angular injectable.providedIn vs module.providers

A Common practice is to include services in @NgModule.providers @NgModule({ providers: [ MessageService ] }) According to Angular tutorial, you can provide a service without specifying it in the @NgModule decorator, by using…
yuval.bl
  • 4,890
  • 3
  • 17
  • 31
7
votes
2 answers

Lazy loading and providers strategy

Right now, using Angular v5, while using lazy loading, I load all my providers in app.module.ts which I guess isn't maybe the best strategy because this won't speed up my app boot time, specially because I've got something like 50 custom providers…
David Dal Busco
  • 7,975
  • 15
  • 55
  • 96
6
votes
1 answer

The semantics of @Injectable(providedIn: 'root')?

Just want to make sure I understand the semantics of @Injectable(providedIn: 'root'). Prior to Angular 6 if we import a module from NPM that contains a service we would declare that module in our app module such that the entire application has…
6
votes
1 answer

When to use Angular 2 factory functions?

I can't imagine a situation where I need to use a factory provider. According to the offical docs https://angular.io/docs/ts/latest/guide/dependency-injection.html the situation is that one may not be able to access a service (service-b) from…
johncol
  • 584
  • 1
  • 7
  • 13
5
votes
2 answers

error:NullInjectorError: No provider for Router

I have to test one component and get this error NullInjectorError: R3InjectorError(DynamicTestModule)[AuthenticationService -> Router -> Router]: NullInjectorError: No provider for Router!**" The component I'm testing have two dependencies and I…
CaneRandagio
  • 366
  • 2
  • 15
5
votes
3 answers

Destroy Angular Service when route change

I have a complexe module called MyPageModule importing several modules which provides Service with following annotation @Injectable( { providedIn: 'root' } ). This module is imported by lazy loading like this: // AppRoutingModule ... { path:…
Kael
  • 858
  • 9
  • 21
5
votes
2 answers

How to inject a dependency into a provider with given injection token?

I'm using an Angular plugin, which needs to be configured by providing a configuration object using an InjectionToken that the plugin exports. import { pluginToken } from 'plugin'; @NgModule({ providers: { // Configure the plugin // …
Robert Kusznier
  • 6,471
  • 9
  • 50
  • 71
5
votes
2 answers

Import a service from another module

I am currently learning the Angular framework (version 5) after developing 2 years with the AngularJS 1.x framework, so I ask myself a lot of questions and one of them is the way to properly import a service provided by another module that the one…
Alexandre D.
  • 711
  • 1
  • 9
  • 28
5
votes
1 answer

Multiple ngrx store in one application

We are developers of a module of a big Angular application. Modules are independent from each other, they are developed by separate teams. We would like to use an ngrx store in our module. An other module already has an ngrx store. If I try to add a…
elcsiga
  • 170
  • 1
  • 8
1
2 3
11 12