Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Javascript library not working on Device

I am using the BigNumber library of MikeMcl to handle my needs for big numbers. I use this library in an Ionic/Angular project.

As explained on Github, the way to install and use this library is to include a script tage in your html:

<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no, width=device-width">
    <title></title>

    <!-- compiled css output -->
    <link href="css/ionic.app.min.css" rel="stylesheet">
    <link href="css/style.css" rel="stylesheet">

    <!-- ionic/angularjs js -->
    <script src="lib/ionic/js/ionic.bundle.min.js"></script>

    <!-- cordova script (this will be a 404 during development) -->
    <script src="lib/ngCordova/dist/ng-cordova.min.js"></script>
    <script src="cordova.js"></script>

    <!-- ********* BIGNUMBER library ********* -->
    <script src='lib/bignumber.js/bignumber.min.js'></script>    

    <script src="js/app.js"></script>
    <script src="js/controllers.js"></script>
    <script src="js/services.js"></script>

  </head>
  <body ng-app="starter">
    <ion-nav-view></ion-nav-view>
  </body>
</html>

Now in my code, I can use this library as for instance:

x = new BigNumber(123.4567)
y = BigNumber('123456.7e-3')
z = new BigNumber(x)
x.equals(y) && y.equals(z) && x.equals(z)      // true

I tested this and it works fine on Chrome and on Safari (even on device).

But when I install the app on my phone, using Phonegap Build, the app does not work anymore (I checked that this library is the cause by removing the BigNumber syntaxes from my code). Moreover, the Angular in the app just crashes and shows for instance {{variableName}} and nothing is working.

Because I develop in a cloud environment, I did try to debug the app using the Safari Developer Debug Console on a mac (by plugging my phone with an USB to the mac and then enabling Developer tools in Safari).

However, no errors were found with exception of one:

file not found: "path/to/ionic/lib/js/angular.min.js.map" 404

But this is not the cause of the problem.

What is going on? How can I still use this javascript library on my device?

like image 889
JohnAndrews Avatar asked Jun 30 '15 08:06

JohnAndrews


1 Answers

I have just tested your code and it doesn't work because when you create the y variable you don't use the word new.

This is the code I've used and it works

x = new BigNumber(123.4567)
y = new BigNumber('123456.7e-3')
z = new BigNumber(x)
alert( x.equals(y) && y.equals(z) && x.equals(z));// I get true
like image 145
jcesarmobile Avatar answered Oct 08 '22 23:10

jcesarmobile