angular2-providers

Angular2: How to inject two instances of the same service into multiple components?

风格不统一 提交于 2019-12-08 09:34:59
问题 Suppose that I have an Angular Service that looks like this: @Injectable() export class Clipboard { constructor(private multiple: Multiple, private di:DI, private injected:Injected, private things: Things){} // The clipboard has local state: private isCut: boolean; private toPaste: Hero; cut(hero: Hero){ this.isCut = true; this.toPaste = hero; } copy(hero: Hero){ this.isCut = false; this.toPaste = hero; } paste(locaction: Location){ // Lots of really complex logic } canPaste(potentialLocation

No runtime provider for RuntimeCompiler

◇◆丶佛笑我妖孽 提交于 2019-12-07 09:53:06
问题 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 '@angular/compiler'; @Component({ moduleId: module.id, selector: 'my-app', templateUrl: 'app.component.html', }) export class AppComponent implements OnInit { constructor(private _runtimeCompiler: RuntimeCompiler) {} ngOnInit() { this._runtimeCompiler

How to provide custom provider to the all lazy loaded modules

笑着哭i 提交于 2019-12-07 01:22:45
问题 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, defaultOptions: RequestOptions, cookieService: CookieService) => new CustomHttp(backend, defaultOptions, cookieService), deps: [XHRBackend, RequestOptions, CookieService] }] My lazy loaded modules do not affect this custom provider. Is there a way to provide it for them

How to provide custom provider to the all lazy loaded modules

[亡魂溺海] 提交于 2019-12-05 05:12:54
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, defaultOptions: RequestOptions, cookieService: CookieService) => new CustomHttp(backend, defaultOptions, cookieService), deps: [XHRBackend, RequestOptions, CookieService] }] My lazy loaded modules do not affect this custom provider. Is there a way to provide it for them too? Without duplication of code in the providers property in the component.module file. Thank you! I've

EXCEPTION: No provider for Headers! (App -> Api -> Headers)

我只是一个虾纸丫 提交于 2019-12-01 16:02:21
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 {ROUTER_PROVIDERS, HashLocationStrategy, LocationStrategy} from 'angular2/router'; import {HTTP_PROVIDERS, HTTP_BINDINGS} from 'angular2/http'; const ENV_PROVIDERS = []; // depending on the env mode, enable prod mode or add debugging modules if (process.env.ENV === 'build') { enableProdMode(); } else { ENV_PROVIDERS.push(ELEMENT_PROBE_PROVIDERS); } /* * App

EXCEPTION: No provider for Headers! (App -> Api -> Headers)

自闭症网瘾萝莉.ら 提交于 2019-12-01 14:43:41
问题 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 {ROUTER_PROVIDERS, HashLocationStrategy, LocationStrategy} from 'angular2/router'; import {HTTP_PROVIDERS, HTTP_BINDINGS} from 'angular2/http'; const ENV_PROVIDERS = []; // depending on the env mode, enable prod mode or add debugging modules if (process.env

Angular2 Module: How can i import a service from another module

微笑、不失礼 提交于 2019-11-30 11:06:00
import { NgModule } from '@angular/core'; import { CommonModule } from '@angular/common'; import { FormsModule } from '@angular/forms'; import { ClinicFacilityService } from './apiClient.module'; @NgModule({ imports: [ CommonModule, FormsModule ], declarations: [ DailyScheduleComponent, ], providers: [ ClinicFacilityService ], exports: [ DailyScheduleComponent ], }) export class ClinicDashboardModule { } I need to import ClinicFacilityService that is declared in another module ( apiClient.module ) Is this even possible, if not why is not possible. At the moment i am importing

What are providers in Angular2?

不问归期 提交于 2019-11-30 07:01:05
问题 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 but still sparse. It currently defines providers as: An array of dependency injection providers for services that the component requires. This recursive definition isn't very helpful. A more detailed explanation with an example would really help. 回答1: