我有将问题注入Angular 2应用程序的问题.几天前它工作正常,但现在我有错误:
原始例外:没有Http的提供商!
有主要的
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic'; import { AppModule } from './app.module'; import { LoginModule } from "./login/login.module"; import { Http } from "@angular/http"; platformBrowserDynamic().bootstrapModule(LoginModule);
登录module.ts
@NgModule({ imports: [BrowserModule, FormsModule], // external modules for all components declarations: [LoginComponent], // component which belong to this module bootstrap: [LoginComponent] // component on load }) export class LoginModule { }
最后在LoginModule中登录LoginComponent
import { Component } from '@angular/core'; import { AccountService } from "../data/account.service"; import { Http, Response, RequestOptions, Headers } from '@angular/http'; import { LocalStorage } from '../storage/storage'; @Component({ selector: 'tp-login', templateUrl: `app/login/login.html`, styleUrls: ['app/login/login.css'], providers: [AccountService, LocalStorage] })
LoginComponent中没有关于没有HttpProvider的异常.Somone知道如何解决这个问题?
很好地将所有模块依赖项封装到@ngModule
属性内的主类模块中
import { BrowserModule } from '@angular/platform-browser'; import {NgModule} from '@angular/core'; import { FormsModule } from '@angular/forms'; import { HttpModule } from '@angular/http'; import { AppComponent } from './app.component'; @NgModule({ declarations: [ AppComponent ], imports: [ BrowserModule, FormsModule, HttpModule, RouterModule.forRoot(appRoutes) ], providers: [], bootstrap: [AppComponent] })
因此,您可以确定当您的模块将作为子依赖项包含时 - 所有依赖项将在之前解决.