angular2-providers

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

给你一囗甜甜゛ 提交于 2019-11-29 16:36:56
问题 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

Angular 2 TestBed with mocks

∥☆過路亽.° 提交于 2019-11-28 22:31:43
问题 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 to use the TestBed . When I provide the mock angular for some reason keep looking for the services that the mock depends on. And throws a DI exception . When I provide all the dependencies the test works but I don't want to repeat myself for each

What are providers in Angular2?

☆樱花仙子☆ 提交于 2019-11-28 22:22:35
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. Sasxa Providers are usually singleton (one instance) objects, that other objects have access to through