Angular ng-view phonegap not working

I am trying to make a basic application with angularjs and phonegap in android. But it doesn't seem to work. The following are the source code files:

index.html

<!DOCTYPE html> <html ng-app="main-app"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"> <title>Insert title here</title> </head> <body> <div class="body-content" ng-controller="MainCtrl"> <div class="loader-ajax" ng-show="isViewLoading"></div> <div ng-view></div> </div> <script src="js/angular.js"></script> <script type="text/javascript" src="js/main.js"></script> <script type="text/javascript" src="cordova-2.3.0.js"></script> <script type="text/javascript" src="js/index.js"></script> <script type="text/javascript"> app.initialize(); </script> </body> </html> 

main.js

 var mobileApp = angular.module("main-app", []); mobileApp.config(function ($routeProvider,$compileProvider) { $routeProvider .when("/", { templateUrl: "partial/home.html", controller: "homeController" }) .when("/home", { templateUrl: "partial/home.html", controller: "homeController" }); $compileProvider.urlSanitizationWhitelist(/^\s*(https?|ftp|mailto|file|tel):/); }); mobileApp.controller("MainCtrl",function($scope){ alert('Coming here'); $scope.isViewLoading=true; }); mobileApp.controller("homeController",function($scope){ alert('Home Coming here'); }); 

index.js

 var app = { initialize: function() { this.bind(); }, bind: function() { document.addEventListener('deviceready', this.deviceready, false); }, deviceready: function() { // note that this is an event handler so the scope is that of the event // so we need to call app.report(), and not this.report() app.report('deviceready'); angular.bootstrap(document, ['main-app']); }, report: function(id) { console.log("report:" + id); } }; 

When the application receives the load, the router does not seem to work because it does not get into the Homecontroller.

From the fact that I'm ready everywhere, this code should work. Any help would be greatly appreciated.

0
source share
3 answers

I had the same problem that I just found a solution to. Take a look at Angular ng-view / routing not working in PhoneGap

+2
source

Move app.initialize(); in deviceready PhoneGap event

0
source

I had this problem - I got stuck on it for 3 evenings - in the end, I compared the pattern names in the routing with the actual file names - make sure the case matches.

0
source

Source: https://habr.com/ru/post/951569/


All Articles