2017-02-15 57 views
4

angular2進口HTTP_PROVIDERSangular2進口HTTP_PROVIDERS錯誤

錯誤信息>> @角/ HTTP /索引「」沒有出口成員 'HTTP_PROVIDERS'。

import { Component } from '@angular/core'; 
import {NoticeService} from './products/product.service'; 
import {HTTP_PROVIDERS} from '@angular/http'; 
import 'rxjs/Rx'; 

@Component({ 
    selector: 'my-app', 
    template: ` 
    <h1>Hello {{name}}</h1> 
    <pm-products></pm-products> 
    `, 
    providers: [NoticeService, HTTP_PROVIDERS] 
}) 

回答

10

你不需要HTTP_PROVIDERS了(不推薦)導入http模塊代替

import { NgModule } from '@angular/core'; 
import { HttpModule } from '@angular/http'; 
import { BrowserModule } from '@angular/platform-browser'; 

import { AppComponent } from './app.component'; 

@NgModule({ 
    imports: [ 
     BrowserModule, 
     HttpModule 
     ], 
    declarations: [AppComponent], 
    providers: [], 
    bootstrap: [AppComponent], 
}) 
export class AppModule { } 
+0

正如我所知道的,有必要使用'http.get'和'http.post'方法嗎? – OPV