I work on a Ionic project (AngularJS + Apache Cordova aka Phonegap).
The first code's lines of my project are 4 months, and yesterday, the application nolonger works on emulators and real devices, but still work into chrome window. So I suppose my angular code is correct, but I don't know where is the issue, and I didn't know how to handle it.
At the beginning I coded directly in my www
folder, and I test it either into chrome with devtools and device emulation, or in chrome with the Apache Ripple extension, and at times I install it into my real device (Nexus S).
I recently installed grunt and bower into my project for common tasks, and I decided to reorganize my project folder.
Then now, I code into a src
folder, and :
www
folder and includes a dedicated index.html linked to scr/
js, html,css and other res files.www
folder and includes build or copy all the needed files to the the app (app.min.css, app.min.js, templates, fonts and media files, icon).Both of it work fine in chrome, but when I build (via either cordova-cli or phonegap build) and install the app on emulator or real device, I get the splash screen and then, a permanent white screen.
I tried to debug it with the help of weinre I and note that the js console doesn't catch any thrown error. But I placed some console.log and it appears that the routing is broken.
angular.module('app').run()
is executed, but the first controller that is AppCtrl is never executed.
Here is my module code (important parts for this post) :
(function(){
angular.module('app', [
'ionic',
'ngCordova',
'app.auth',
'app.model',
'app.action',
// 'app.test',
])
.run(['$ionicPlatform',
function($ionicPlatform) {
alert("app.run() runs ...");
}])
.config(['$stateProvider','$urlRouterProvider',
function($stateProvider, $urlRouterProvider) {
var tmplt_dir = 'modules/app/tmplt';
var tmplt = function(viewName){
return tmplt_dir + '/' + viewName + '.html' ;
};
$stateProvider
.state('app', {
url: "/app",
abstract: true,
templateUrl: tmplt('app') ,
controller: 'AppCtrl'
})
.state('app.main', {
url: "/main",
abstract: false,
views: {
"menuContent" : {
templateUrl: tmplt('main') ,
controller: 'MainCtrl'
}
}
})
.state('app.main.home', {
url: "/home",
views: {
'homeTabContent' :{
templateUrl: tmplt('home') ,
controller: 'HomeCtrl'
}
}
});
// if none of the above states are matched, use this as the fallback
$urlRouterProvider.otherwise('/app/main/home');
}])
.controller('AppCtrl', [ '$rootScope', '$cordovaToast', '$window',
function($rootScope, $cordovaToast, $window) {
alert('AppCtrl runs...');
$rootScope.notImplementedException = function(){
var message = "Bientôt disponible.";
try {
$cordovaToast.showShortCenter(message);
} catch(e){
alert(message);
}
};
$rootScope.browserOpen = function(href){
var ref = $window.open(href, '_system', 'location=yes');
};
}])
.controller('MainCtrl', [ function() {
alert('MainCtrl runs...');
}])
.controller('HomeCtrl', [ '$rootScope','$auth', '$app',
function($rootScope, $auth, $app) {
alert('HomeCtrl runs...');
if (!$auth.checkLogin()) {
$auth.authError();
}
$rootScope.appName = $app.name;
}])
})();
The only alerts that appears is :
So, the alerts that don't appear are :
Remember that in chrome, all works perfectly !
This issue is really baffling and I've already lost a few hours to track it, unsuccessfully.
Any idea ?
I solved my problem.
In fact, I wrote an httpRequestInterceptor factory which check if an url have to be signed to use my Rest API.
A recent change of the structure of my project folder causing this factory returning sometimes a wrong result, then signing some local url and causing bad routing, then whitescreen.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With