Angular 4服务模块在App Module中正确导入

时间:2017-07-15 10:46:28

标签: angular

如何在Angular AppModule中导入我的服务模块。我得到了core.es5.js:1020 ERROR错误:未捕获(在承诺中):错误:没有ConnectionBackend的提供者!还有HttpService。我尝试在AppModules提供程序中添加HttpService,但ConnectionBackend仍然存在问题。

    import { NgModule } from '@angular/core';
import { HttpModule, XHRBackend, RequestOptions } from '@angular/http';
import { RouterModule, Router } from '@angular/router';
import { CommonModule } from '@angular/common';
import { Regex } from './helper/regex.constants';
import { LoaderComponent } from './loader/loader.component';
import { LoaderService } from './loader/loader.service';
import { StorageService } from './storage/storage.service';
import { SessionStorage } from './storage/session.storage';
import { LocalStorage } from './storage/local.storage';
import { HttpService } from './rest/http.service';
import { httpServiceFactory } from './rest/http.factory';

@NgModule({
    imports: [CommonModule, HttpModule, RouterModule],
    exports: [HttpModule, LoaderComponent],
    declarations: [LoaderComponent],
    providers: [StorageService, SessionStorage, LocalStorage, 
                {
                    provide: HttpService,
                    useFactory: httpServiceFactory,
                    deps: [XHRBackend, RequestOptions, Router, LoaderService, StorageService]    
                }

               ]

})
export class ServicesModule { }

0 个答案:

没有答案