Questions tagged [angular2-providers]

52 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
  • 543
  • 4
  • 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,259
  • 4
  • 12
  • 18
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
  • 195
  • 1
  • 2
  • 9
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
  • 639
  • 1
  • 13
  • 31
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,403
  • 15
  • 42
  • 72
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
  • 3,405
  • 6
  • 44
  • 75
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
  • 392
  • 7
  • 27
0
votes
1 answer

Do app.module providers and components share the same instance of an Injectable?

When I add the injectable CameraChannelService into ngModule's provider array: import { CameraChannelService } from './camera-channel.service'; @NgModule({ declarations: [ AppComponent, BabylonWallpaperDirective, MenuComponent, …
0
votes
1 answer

Provide an object to a service

I'm trying to use a service implement by another person (github). This service requires that a configuration be passed to it. According to the repo: You have to configure Neo4jSettings in your bootstrap: provide('Neo4jSettings', {useValue: { …
0
votes
1 answer

Angular 2 Provider exception

When injecting service into component, I'm seeing the error: One or more of providers "CategoriesComponent" were not defined: [?, [object Object], BrowserXhr, [object Object], [object Object], XHRBackend, [object Object]]. Please help me to…
user3027246
  • 233
  • 6
  • 13