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.)
The code is like this:
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;
});
}
}
First, the error was for "Http". Then I (think I) solved with this:
@Component({
selector: 'page-home',
providers: [Http],
templateUrl: 'home.html'
})
But now the error is a "No provider for ConnectionBackend!", and I don't know how to solve.
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 {
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.