Reputation: 7004
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?
Upvotes: 8
Views: 1378
Reputation: 7004
Found the solution. If you are also experiencing that a javascript library is not working on your device, but it does in the browser, then this answer might help you.
The problem occured that when I ran npm install
to install the package, that it did not update my .git dependencies properly. What happened is that every time I packaged my app through Github and Phonegap Build, the folder of BigNumber was not taken into account. So basically, the file bignumber.js
was not available in the app and thats why it did not work.
I solved it by copying all the files from the BigNumber folder to a new custom folder.
A related question is here: Git not pushing all files and folders
Upvotes: 0
Reputation: 53361
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
Upvotes: 1
Reputation:
@JohnAndrews,
If this is the extent of your code, it is missing the deviceready listener. On cordova/phonegap you typically cannot do stuff, until you get the deviceready event. So, this is the only thing I can think of, Can you add a function onDeviceReady() {}
and see if that fixes your problem?
Oh and, of course, make sure you run your operations AFTER this event.
Upvotes: 0