Ionic 2 - ng2-chartjs2 working in browser but not in device

I managed to implement ng2-chartjs2 in the ionic2 application. It works fine when I launch it in a browser (e.g. ionic or ionic running android -l -c), but when I tried it on a device (e.g. android ionic running), it just shows a blank page.

I uploaded a working sample project in my repo here

Any help would be greatly appreciated. Thanks.

Still expecting someone to clear this issue.

+1
source share
1 answer

Well, the problem is that Chart.bundle.js is not on the expected path in the Android assembly.

Add this:

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)); } }); }); } } 

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

Good luck

+2
source

Source: https://habr.com/ru/post/1258403/


All Articles