Reputation: 1435
As mentioned in title, the function won't be triggered when register the callback function using $ionicPlatform.ready or ionic.Platform.ready
Upvotes: 0
Views: 859
Reputation: 1435
The reason is because ionic.Platform is using 'load' event to register the 'deviceready' event. Since requireJS is used, the 'load' event will be triggered before ionic get chance to hook the 'load' event. Then ionic miss the 'deviceready' event. The solution is pretty simple, just trigger another 'load' event to let ionic calls itself initialization callback function or register your own 'deviceready' handler directly on the document.
window.addEventListener("load", onWindowLoad, false);
Using the following code to test it out
<body onload="console.log('body onload triggered')">
<script src="bower_components/requirejs/require.js"></script>
<script src="scripts/requirejsconfig.js"></script>
<script src="cordova.js"></script>
</body>
In the 'requirejsconfig.js'
//pre-load the non AMD libraries for the r.js optimization
require([ 'domReady!',
'angular',
'ionic',
'ngIonic',
...
],
function (document, ng, ionic)
{
'use strict';
console.log('call ionic Platform ready');
ionic.Platform.ready(function ()
{
'use strict';
ng.bootstrap(document, ['app']);
});
});
The output in chrome will be
The output in Xcode5.1 will be (the HTML log info is gone, because of the cordova reset which is before 3th)
Upvotes: 1