Questions tagged [angular2-providers]

55 questions
1
vote
1 answer

Angular 2 - Using "multi" provider to override Http

I want to override Http with a custom class, say HttpClient to do some operations before a request and after a response, however I don't want to have to remember to import that class instead of the platform http class. I've been experimenting with…
D_Naish
  • 513
  • 3
  • 20
1
vote
2 answers

How to import Javascript library in angular2 globally

I'm trying to import the moment.js library in angular2. I found the following solution as: import {Component} from 'angular2/core'; import * as moment from 'moment'; @Component({ selector: 'app', template:…
kdu
  • 1,179
  • 1
  • 11
  • 18
0
votes
0 answers

Angular initialise module with configuration with remote http call

I'm using the GoogleApiModule to provide authentication for users, however I don't want to have the clientId stored directly into the angular code what I would like it to retrieve the information from a remote configuration server (using HttpClient)…
ufasoli
  • 952
  • 2
  • 16
  • 35
0
votes
0 answers

DI Providers: how to preemptively know if i forget providing a service

I have multiple components that needs some services provided with useFactory; these services aren't provided in root, so if i don't provide them in the component's providers array, i will get an error only at runtime: is it possible to move this…
Diak
  • 3
  • 2
0
votes
2 answers

Is Singleton Instance of a service provided to child components?

Suppose there is a parent component P . Having two child components B and C . I provide a service (MyService let's say) in the ElementInjector of P and Inject the service in the constructor of P component class. I Inject the service again in the two…
0
votes
1 answer

Can't resolve all parameters for Component when dependency is registered within a service via providedIn option?

I've been playing with DI in Angular and can't figure out why I run into an error when specifying a service to be provided in module via providedIn. First off, I created SharedModule, declared there SharedComponent and configured SharedService as…
fekaloid
  • 173
  • 1
  • 1
  • 6
0
votes
1 answer

serviceFactory as a dependecy (deps: []) in Provider Object - is it possible?

I got provider in app.module defined as follows: { multi: true, deps: [ServiceA, ServiceB], provide: HTTP_INTERCEPTORS, useClass: HttpResponseInterceptor, } And it…
ppotera
  • 61
  • 5
0
votes
0 answers

Angular 2 - Singleton service causing injection problems with other service

I have a lot of code, but I'll try to cut it down. I am trying to transform a service into a singleton service (TagService). But this seems to be causing problems. I have lots of components and services, but I'll simplify it down to…
0
votes
1 answer

Angular2 Routing-Resolve interface usage with OpaqueToken

I want to fetch data before an route/component is instantiated. Therefore I want to use the "Resolver"-Interface from the Angular2-Routing-Module. Take a look at my code. Its working with a string as the provider name, but throwing errors if I use…
0
votes
1 answer

Ionic 2: How to call Provider function in Controller class

I have created new Cordova Plugin only on my machine. Then I added it to my project. It is working fine when I call that plugin. Now, I tried to make a structured caller for my plugin. I created a Provider for it, but the problem is I don't know how…
siti aishah ismail
  • 459
  • 11
  • 25
0
votes
3 answers

Angular 2 import path not working properly

I have a service that I injected into my app component. app.component.ts import { Component } from '@angular/core'; import {ProductService} from '../../../products/Classes/Product.Service'; import {TestService } from…
David
  • 5,013
  • 14
  • 38
  • 65
0
votes
1 answer

Provider inside provider in Ionic2/ Angular2 Application

I am having two provider. AppStorage which is responsible for setting and getting values from storage. import { Injectable } from '@angular/core'; import {Http, Headers, RequestOptions} from '@angular/http'; import {Observable} from…
0
votes
1 answer

Angular 2 - 404 provider issue

I'm having a problem while I'm trying to add a provider in my Angular 2 application. I was trying some solutions I found online but I can't figure out what is going on with my app. Basically I'm getting the problem when I add the provider to my…
gon250
  • 2,766
  • 3
  • 34
  • 69
0
votes
1 answer

Detect locale and set it on angular 2 root module using provider

I have a function to detect current locale and I need to set the locale at angular 2 rooot App module via provider. so that i can use that in all other components. I know i can able to do this like below. { provide: 'Locale', useValue: 'en-US'…
chenk
  • 372
  • 7
  • 26