Questions tagged [angular2-providers]

55 questions
50
votes
5 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
  • 8,544
  • 14
  • 63
  • 91
25
votes
2 answers

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, …
Kimaina Allan
  • 317
  • 1
  • 4
  • 11
24
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…
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…
sreginogemoh
  • 7,997
  • 18
  • 71
  • 125
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
  • 1,929
  • 5
  • 25
  • 51
7
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
  • 22,895
  • 9
  • 62
  • 76
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,…
Mikki
  • 6,751
  • 5
  • 31
  • 49
7
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
  • 543
  • 1
  • 7
  • 26
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
  • 2,393
  • 5
  • 21
  • 34
5
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:…
5
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…
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
  • 12,832
  • 24
  • 97
  • 139
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
  • 9,942
  • 32
  • 97
  • 181
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
  • 249
  • 5
  • 19
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…
1
2 3 4