Questions tagged [angular2-providers]
52 questions
58
votes
6 answers
What are providers in Angular2?
In the Angular2 component configuration providers is one of the keys that we could specify. How are these providers defined and what are they used for?
@Component({
..
providers: [..],
..
})
Note:
Angular2 documentation is gradually maturing…

Pranjal Mittal
- 10,772
- 18
- 74
- 99
32
votes
5 answers
Angular: Lazy loading modules with services
I've been following this tutorial, to understand lazy loading, and below is my inference.
Scenario 1: Services are provided by putting them in the providers array of a child module
Scenario 2: Services are provided in a child module using the…

karthikaruna
- 3,042
- 7
- 26
- 37
28
votes
1 answer
Angular2 Module: How can i import a service from another module
import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { FormsModule } from '@angular/forms';
import { ClinicFacilityService } from './apiClient.module';
@NgModule({
imports: [
CommonModule,
…

Allan Kimaina
- 347
- 2
- 4
- 11
10
votes
2 answers
EXCEPTION: No provider for Headers! (App -> Api -> Headers)
Just cant figure out why I have still getting this missing Headers provider issue.
My bootstrap.ts:
import {enableProdMode, provide} from "angular2/core";
import {bootstrap, ELEMENT_PROBE_PROVIDERS} from 'angular2/platform/browser';
import…

Sergino
- 10,128
- 30
- 98
- 159
9
votes
3 answers
Angular2, AoT compilation: Cannot determine the module for component AppComponent
Summary: I am trying to use Angular2 AoT for my Angular2 application, but since I have static providers to pass some values from server to Angular2, ngc shows some errors. My problem is how to get the ngFactory files created using ngc.
Details: I am…

Musa Haidari
- 2,109
- 5
- 30
- 53
8
votes
1 answer
Override components , like services?
Say we import one of Angular Material modules :
providers:[],
imports : [MaterialInput]
Inside MaterialInput , there is a component used named : MaterialInputComponent
For some reasons I want to override that component with my own
So I want to…

Milad
- 27,506
- 11
- 76
- 85
8
votes
2 answers
Angular 2 TestBed with mocks
I am trying to test a component which uses another service. And I want to isolate the component by providing a mock for the service. Before RC5 I can simply use addproviders which is now deprecated and will be removed by the next RC. Instead I have…

LonsomeHell
- 573
- 1
- 7
- 29
7
votes
1 answer
How to provide custom provider to the all lazy loaded modules
I am using Lazy Loading strategy of subcomponents in my application. On the top level of application, I have custom HTTP provider which intercept all ajax calls.
providers:[{
provide: Http,
useFactory: (backend: XHRBackend,…

Kanso Code
- 7,479
- 5
- 34
- 49
6
votes
2 answers
NullInjectorError: No provider for t
Greeting, I'm trying to build my angular2 project with "ng build --prod --configuration=production", deploy it on ubuntu server and I got this error in the web console :
ERROR Error: "StaticInjectorError[t -> t]:
StaticInjectorError(Platform:…

Shidomaru NeveRage
- 256
- 5
- 19
6
votes
1 answer
Angular: ng build --prod "Cannot determine the module for class. Add class to the NgModule to fix it"
I have placed my pagination logic in a separate module and importing it in AppModule. Below is my code for my pagination module and AppModule.
PagingUtilitiesModule:
import { NgModule, ModuleWithProviders, Injector } from '@angular/core';
import {…

karthikaruna
- 3,042
- 7
- 26
- 37
6
votes
1 answer
No Provider for AuthHttp! Angular2-Jwt provider issue
At least I thought I was providing correctly. Below are the relevant snippets of my app.module file and the service in which I use AuthHttp. I followed the configuration in the ReadMe for creating the factory method to provide for AuthHttp, but…

ruhrohraggy
- 89
- 3
5
votes
1 answer
How can I add providers to a Service class in Angular 2?
I have a component that uses a service. The component looks something like this:
@Component({
moduleId: module.id,
selector: 'test',
providers: [HTTP_PROVIDERS, TestService]
})
export class TestComponent implements OnInit {
…

Carven
- 14,988
- 29
- 118
- 161
4
votes
4 answers
No runtime provider for RuntimeCompiler
I'm trying to follow the accepted answer here, and make a call to RuntimeCompiler.clearCache()
Here's how I've tried to do it:
import { Component } from '@angular/core';
import { OnInit } from '@angular/core';
import { RuntimeCompiler } from…

Juicy
- 11,840
- 35
- 123
- 212
3
votes
2 answers
Angular 2 - append withCredentials = true with every http request
I am using angular 2 (not latest as using through angular-cli: 1.0.0-beta.11-webpack.9-4) and I have to set withCredentials to true for every http request. I tried to set it up for one request using
http.get('http://my.domain.com/request', {…

Jay
- 299
- 1
- 5
- 20
2
votes
1 answer
Why does ', providers: [TravelService] ' in a component prevent the RXJS Behaviour subject from sharing data across components?
@Component({
selector: 'app-overview-travel',
templateUrl: './overview-travel.component.html',
styleUrls: ['./overview-travel.component.scss'],
providers: [TravelService]
})
The code above prevented data from my shared data service (using…

Panthar
- 71
- 4