我正在尝试将json文件数据读取到我的Html页面,但是没有为ConnectionBackend提供服务器!
见下面的代码
Home.ts
import { Component } from '@angular/core';
import { NavController ,Platform} from 'ionic-angular';
import { SampleDataService } from '../../providers/sample-data-service';
@Component({
selector: 'page-home',
templateUrl: 'home.html'
})
export class HomePage {
myjsondata:any;
constructor(public navCtrl: NavController, platform: Platform,
sampleDataService:SampleDataService) {
sampleDataService.getJsonData().subscribe((data) => {
console.log("what is in the data ", data);
this.myjsondata = data;
});
}
ngOnInit(){}
}
app.component.ts
import { SampleDataService } from '../providers/sample-data-service';
import { Http } from '@angular/http';
@Component({
templateUrl: 'app.html',
providers:[SampleDataService,Http]
})
export class MyApp {
@ViewChild(Nav) nav: Nav;
rootPage: any = HomePage;
pages: Array<{title: string, component: any}>;
constructor(public platform: Platform, public statusBar: StatusBar,
public splashScreen: SplashScreen, sampleDataService:SampleDataService,
http:Http) {
statusBar.styleDefault();
sampleDataService.getJsonData();
this.initializeApp();
app.module.ts
import { SampleDataService } from '../providers/sample-data-service';
import { Http} from '@angular/http';
@NgModule({
declarations: [
MyApp,
HomePage,
ListPage,
About,
Contact,
AboutCity
],
imports: [
BrowserModule,
IonicModule.forRoot(MyApp)
//AutoCompleteModule,
],
bootstrap: [IonicApp],
entryComponents: [
MyApp,
HomePage,
ListPage,
About,
Contact,
AboutCity
],
providers: [
StatusBar,
SplashScreen,
{provide: ErrorHandler, useClass: IonicErrorHandler},
SampleDataService,
Http
]
})
我尝试了很多,但没有得到解决方案为什么会出现此错误。 可以请任何人帮助我。
答案 0 :(得分:1)