我想在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
我有谷歌搜索过,但无法解决。
答案 0 :(得分:0)
在www / assets / i18n /中创建本地化文件: WWW /资产/ I18N / es.json
JSON文件应如下所示:
{
"键" :"翻译键#34;,
"嵌套":{
"用户":"用户",
"登录":"登录",
" signUp":"注册"
}
}
app.ts并设置所需的配置。首先是所需的进口。 现在将provider和pipe添加到ionicBootstrap方法