Ionic 2 - ng2-chartjs2在浏览器上工作但在设备中没有 [英] Ionic 2 - ng2-chartjs2 working on browser but not in device

查看:209
本文介绍了Ionic 2 - ng2-chartjs2在浏览器上工作但在设备中没有的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已设法在我的ionic2应用程序中实现ng2-chartjs2。当我在浏览器上运行它(即离子服务或离子运行android -l -c)时它完全正常工作但是当我在设备上尝试它(即离子运行android)时,它只是显示一个空白页面。

I have managed to implement ng2-chartjs2 in my ionic2 application. It is perfectly working when i run it on browser (i.e ionic serve or ionic run android -l -c) but when i tried it on device (i.e ionic run android), it simply shows a blank page.

我已在我的仓库中上传了的工作示例项目这里

I have uploaded the working sample project in my repo here

任何帮助将不胜感激。谢谢。

Any help would be appreciated. Thanks.

仍然希望有人清除此问题。

Still expecting someone to clear this issue.

推荐答案

那么问题是Chart.bundle.js不在android构建的预期路径上。

Well the issue here is that the Chart.bundle.js isn't on the expected path on android build.

添加:

var availablePlatforms = (process.env.CORDOVA_PLATFORMS ? process.env.CORDOVA_PLATFORMS.split(',') : []);

var filestocopy = [
  {"src/assets/libs/Chart.bundle.js": "platforms/android/assets/libs/Chart.bundle.js"}
];

for(var x=0; x<availablePlatforms.length; x++) {

  var currentPlatform = availablePlatforms[x].trim().toLowerCase();

  if (currentPlatform == 'android') {
    filestocopy.forEach(function(obj) {
      Object.keys(obj).forEach(function(key) {
        var val = obj[key];
        var srcfile = path.join(rootdir, key);
        var destfile = path.join(rootdir, val);
        var destdir = path.dirname(destfile);
        if (fs.existsSync(srcfile) && fs.existsSync(destdir)) {
          fs.createReadStream(srcfile).pipe(
              fs.createWriteStream(destfile));
        }
      });
    });

  }
}

在你的<$结束时c $ c> hooks - > after_prepare - > 010_add_platform_class.js ,然后将 index.html 内的脚本引用更改为< script src =assets / libs / Chart.bundle。 js>< / script> (注意:图表更改了图表)。

At the end of your hooks -> after_prepare -> 010_add_platform_class.js, then change the script reference inside of your index.html to <script src="assets/libs/Chart.bundle.js"></script> (note: changed chart for Chart).

祝你好运!

这篇关于Ionic 2 - ng2-chartjs2在浏览器上工作但在设备中没有的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆