[英]No provider for Http! but the Module is imported
I'm trying to use the http module. 我正在尝试使用http模块。 After looking around for a bit I saw that the only two options for fixing this were to import the module (which i've done) or use HTTP_PROVIDERS which is deprecated for me. 环顾了一下之后,我看到解决此问题的仅有的两个选择是导入模块(我已经完成)或使用对我而言已弃用的HTTP_PROVIDERS。
I've imported it here: 我在这里导入了它:
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 { }
and this is my boot.ts 这是我的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
]);
And i'm trying to use it here : 我正在尝试在这里使用它:
import {Injectable} from '@angular/core';
import {Headers,Http} from '@angular/http';
@Injectable()
export class ApiService {
constructor(private _http:Http){}
}
but for some reason It's giving me the error: EXCEPTION: Error: Uncaught (in promise): EXCEPTION: Error in :0:0 ORIGINAL EXCEPTION: No provider for Http! 但是由于某种原因,它给了我错误:EXCEPTION:错误:未捕获(承诺):EXCEPTION:错误:0:0原始EXCEPTION:没有Http的提供程序!
The are the versions i'm using: 是我正在使用的版本:
"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"
},
any clue why I would still be getting this error after importing the module? 有什么线索为什么我在导入模块后仍然会收到此错误?
If I remember correctly, NgModule
was introduced in RC.5. 如果我没记错的话, NgModule
中引入了NgModule。 But your dependencies is still using RC.1. 但是您的依赖项仍在使用RC.1。
The current version of Angular2 is 2.0.1. Angular2的当前版本是2.0.1。
I will suggest following: 我建议如下:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.