0
我試圖使用http模塊。看了一下後,我發現只有兩個選項可以導入模塊(我已經完成了)或者使用了HTTP_PROVIDERS,這是我棄用的。沒有Http的提供者!但模塊是進口
我在這裏導入它:
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { HttpModule } from "@angular/http";
import { AppComponent } from './app.component';
@NgModule({
imports: [BrowserModule, HttpModule],
declarations: [AppComponent],
bootstrap: [AppComponent]
})
export class AppModule { }
,這是我boot.ts
import 'core-js';
import 'zone.js/dist/zone';
import {bootstrap} from '@angular/platform-browser-dynamic';
import {ROUTER_PROVIDERS} from '@angular/router';
import {AppComponent} from './app.component';
bootstrap(AppComponent, [
ROUTER_PROVIDERS
]);
而且我想在這裏使用它:
import {Injectable} from '@angular/core';
import {Headers,Http} from '@angular/http';
@Injectable()
export class ApiService {
constructor(private _http:Http){}
}
但由於某種原因它給了我錯誤:EXCEPTION:錯誤:未捕獲(承諾):EXCEPTION:錯誤:0:0 ORIGINAL E XCEPTION:沒有Http的提供者!
的是我使用的版本:
"dependencies": {
"@angular/common": "2.0.0-rc.1",
"@angular/compiler": "2.0.0-rc.1",
"@angular/core": "2.0.0-rc.1",
"@angular/http": "^2.0.1",
"@angular/platform-browser": "2.0.0-rc.1",
"@angular/platform-browser-dynamic": "2.0.0-rc.1",
"@angular/router": "2.0.0-rc.1",
"es6-shim": "^0.35.0",
"reflect-metadata": "0.1.3",
"rxjs": "5.0.0-beta.6",
"systemjs": "^0.19.27",
"zone.js": "^0.6.12"
},
任何線索,爲什麼我仍然會導入模塊後收到此錯誤?
這是一個直接複製/ pa你的package.json中的ste?直到'rc.5','@ NgModule'不存在。你也有'http:^ 2.0.1',其餘的都是'rc.1'。它們不兼容。如果這是一個新項目,只需從「2.0.1」開始。 – cdbajorin