2017-02-16 43 views

回答

6

HTTP-PROVIDERS不再使用。改爲將HttpModule導入您的ngModule,並將其添加到您的導入。

import { HttpModule } from '@angular/http'; 

@NgModule({ 
    imports: [ 
    ... 
    HttpModule, 
    ], 
    declarations: [...], 
    bootstrap: [ .. ], 
    providers: [ ... ], 
}) 

我建議你總是檢查angular.io頁面的當前信息。例如,HTTP的here使用而這被描述:)

在要使用HTTP服務所需要的一切,您導入Http,並在構造函數注入它:

import { Http } from '@angular/http'; 

// ... 

constructor(private http: Http) { } 
+0

然後我應該使用哪個供應商爲HttpServices @ AJT_82 –

+0

該HttpModule包括:) :)我的答案也更新了一點。檢查我提供的鏈接,它有你需要在你的應用程序中使用Http的所有信息:) – Alex

+0

非常感謝@ AJT_82 –

0

你主模塊應導入HttpModule ,其中包含HTTP提供程序。這是最近的做法。

import { HttpModule } from '@angular/http'; 

@NgModule({ 
    declarations: [], 
    imports: [ 
    // ..., 
    HttpModule, 
    ], 
    providers: [], 
}) 
export class AppModule{ 
} 
+0

然後我應該使用哪個供應商爲HttpServices @ mathias247 –

0

只是添加,有時會發生錯字錯誤。 其具體爲HttpModule不是HTTPModule或HTTPmodule或其他。

相關問題