0
在我的計算機上使用「ionic serve」時,我能成功從嵌入到項目中的JSON文件提取JSON數據並查看數據。 (這在我的Mac上使用離子服務在本地工作) 我在爲XCode中的IOS構建後遇到問題。 我將生成的項目導入到XCode中(正如我以前成功完成的),但在XCode中運行或在iPhone上運行時,JSON不再可見。Ionic 2,Xcode和JSON:無法顯示JSON數據
我正在運行最新版本的所有內容並在Mac上工作。
有人可以告訴我我可能做錯了什麼或我失蹤了嗎?
再次感謝您的幫助!
我包括下面我的代碼片段:
**src/assets/data/kjv.json**
JSON file location
**src/providers/my-data/my-data.ts:**
import { Injectable } from '@angular/core';
import { Http } from '@angular/http';
import 'rxjs/add/operator/map';
@Injectable()
export class MyData {
constructor(public http: Http) {
}
getLocalData(){
return this.http.get('../../assets/data/kjv.json');
}
}
**src/pages/home/home.ts:**
import { Component } from '@angular/core';
import { NavController } from 'ionic-angular';
import { MyData } from '../../providers/my-data/my-data';
import { ChaptersPage } from '../chapters/chapters';
@Component({
selector: 'page-home',
templateUrl: 'home.html'
})
export class HomePage {
items: any;
constructor(public navCtrl: NavController, public myService: MyData) {
}
ionViewDidLoad(){
this.myService.getLocalData().map(res => res.json()).subscribe(data => {
this.items = data;
});
}
nextPage(bookNo){
localStorage.setItem('bookNumber', bookNo);
this.navCtrl.push(ChaptersPage);
}
}
**src/app/app.module.ts:**
import { NgModule, ErrorHandler } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { HttpModule } from '@angular/http';
import { IonicApp, IonicModule, IonicErrorHandler } from 'ionic-angular';
import { MyApp } from './app.component';
import { AboutPage } from '../pages/about/about';
import { ContactPage } from '../pages/contact/contact';
import { HomePage } from '../pages/home/home';
import { ChaptersPage } from '../pages/chapters/chapters';
import { VersesPage } from '../pages/verses/verses';
import { TabsPage } from '../pages/tabs/tabs';
import { StatusBar } from '@ionic-native/status-bar';
import { SplashScreen } from '@ionic-native/splash-screen';
import { MyData } from '../providers/my-data/my-data';
@NgModule({
declarations: [
MyApp,
AboutPage,
ContactPage,
HomePage,
ChaptersPage,
VersesPage,
TabsPage
],
imports: [
BrowserModule,
IonicModule.forRoot(MyApp),
HttpModule
],
bootstrap: [IonicApp],
entryComponents: [
MyApp,
AboutPage,
ContactPage,
HomePage,
ChaptersPage,
VersesPage,
TabsPage
],
providers: [
StatusBar,
SplashScreen,
{provide: ErrorHandler, useClass: IonicErrorHandler},
MyData
]
})
export class AppModule {}