Angular 2:没有ConnectionBackend的提供者!怎么解决? [英] Angular 2: No provider for ConnectionBackend! How to solve?
本文介绍了Angular 2:没有ConnectionBackend的提供者!怎么解决?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
I was following this tutorial here https://tableless.com.br/criando-uma-aplicacao-movel-com-ionic-2-e-angular-2-em-dez-passos/ but things dind't go as expectend and I got stuck in a "No provider for..." error. (The tutorial is in Portuguese, but I think you'll get it only by looking at the code examples.)
代码如下:
import { Component } from '@angular/core';
import { NavController } from 'ionic-angular';
import { Http } from '@angular/http';
import 'rxjs/add/operator/map';
@Component({
selector: 'page-home',
templateUrl: 'home.html'
})
export class HomePage {
public feeds: Array<string>;
private url: string = "https://www.reddit.com/new.json";
constructor(public navCtrl: NavController, public http: Http) {
this.http.get(this.url).map(res => res.json())
.subscribe(data => {
this.feeds = data.data.children;
});
}
}
首先,错误是由于"Http"引起的. 然后我(认为我)解决了这个问题:
First, the error was for "Http". Then I (think I) solved with this:
@Component({
selector: 'page-home',
providers: [Http],
templateUrl: 'home.html'
})
但是现在错误是没有为ConnectionBackend提供程序!",我不知道如何解决.
But now the error is a "No provider for ConnectionBackend!", and I don't know how to solve.
推荐答案
您需要将HttpModule添加到app.module中的导入中.
You need to add the HttpModule to the imports in the app.module.
@NgModule({
imports: [
HttpModule, <----
BrowserModule,
HttpModule,
],
declarations: [AppComponent],
providers: [],
bootstrap: [AppComponent],
})
export class AppModule {
}
这篇关于Angular 2:没有ConnectionBackend的提供者!怎么解决?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文