Issue with using ng-persist

Hello,

I am trying to use the ng-persist with the KeyChain plugin.
When I inject the $persist service I get the following error:
TypeError: undefined is not an object (evaluating ‘window.device.platform’), http://192.168.56.1:8100/lib/ionic/js/ionic.bundle.js, Line: 13243

Any ideas ?

Thanks in advance

are you using it on the device or browser? If it is on device, then try running without live reload.

In the browser $persist works fine. When error occurred when I run the app both in iOS simulator and in the device

then you need to check the safari debugger for the exact problem.

I am having this exact same problem, and it’s coming from these two lines in the libraries’ ng-persist.js file.

isAndroid = window.device.platform === "Android";
isIos = window.device.platform === "iOS";

Still trying to solve it, but not too sure how and any advice would be fantastic.

Alright, I think I fixed it.

It looks like ng-persist requires the cordova Device plugin, which window.device.platform is referencing.

So try installing it with

cordova plugin add org.apache.cordova.device

If that doesn’t work try rebuilding ios again, that seemed to work for me.

edit: might have spoke too soon, I’m getting some crashing now (but it might be unrelated). The error seems to come back sporadically but that might be also unrelated. Let me know if this solution solves your problems 100%.

Well, if you’re still dealing with this I think I’ve finally got it. The device plugin needs to be installed like I mentioned in my last post, but at least for me, the cordova plugins weren’t installed by the time the app started.

I used the method djett posted in this thread to make sure they were all loaded before the app fired up. Window.cordova

I added this right before the closing head tag and removed ng-app from the body tag.

<script type="text/javascript">
 (function (window, document, angular) {
   'use strict';

   window.ionic.Platform.ready(function () {
     angular.bootstrap(document, ['APP NAME HERE']);
   });
 }(window, document, angular));
 </script>

After running it a bunch both on emulator and device it seems to be finally working properly.

Thank you so much. Just saved me debugging for the next few hours. I just had exactly the same issue, ios only.