簡體   English   中英

如何在ionic2中導入json文件

[英]How to import json file in ionic2

我想在我的Ionic2項目中導入一個json文件。 在我的home.ts文件中,我有

import * as data from '../../assets/i18n/en.json';

在src文件夾中的declarations.d.ts中,我有:

declare module '*.json' {
    const value: any;
    export default value;
}
declare module '*';

當我執行“離子服務”時,我收到以下錯誤,並且頁面未在瀏覽器中加載。

C:\Users\cju\Documents\Projects\Bus-DriverApp-Tabs>ionic serve

> ionic-hello-world@ ionic:serve C:\Users\cju\Documents\Projects\Bus-DriverApp-Tabs
> ionic-app-scripts serve

[14:20:18]  ionic-app-scripts 0.0.45
[14:20:18]  watch started ...
[14:20:18]  build dev started ...
[14:20:18]  clean started ...
[14:20:18]  clean finished in 5 ms
[14:20:18]  copy started ...
[14:20:18]  transpile started ...
[14:20:22]  build dev failed: Cannot read property 'indexOf' of undefined
[14:20:22]  copy finished in 4.45 s
[14:20:23]  watch ready in 4.48 s
[14:20:23]  dev server running: http://localhost:8100/

這是我的離子信息。

C:\Users\ccc\Documents\Projects\Bus-DriverApp-Tabs>ionic info

Your system information:

ordova CLI: 6.4.0 
Ionic Framework Version: 2.0.0-rc.3 
Ionic CLI Version: 2.1.8 
Ionic App Lib Version: 2.1.4 
Ionic App Scripts Version: 0.0.45 
ios-deploy version: Not installed 
ios-sim version: Not installed 
OS: Windows 7 Node Version: v6.9.1 
Xcode version: Not installed

我有谷歌搜索過,但無法解決它。

在www / assets / i18n /:www / assets / i18n / es.json中創建本地化文件

JSON文件應如下所示:{“key”:“Key for Key”,
“嵌套”:{
“user”:“User”,“signIn”:“登錄”,“signUp”:“注冊”}}

app.ts並設置所需的配置。 首先是所需的進口。 現在將provider和pipe添加到ionicBootstrap方法

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM