I've been trying to build a hybrid web app using Worklight and AngularJS and I'm having trouble getting the navigation working on a device.
I have a simple main screen with a single button. Once I click this button it should take me to page 2 (serviceList page). When I press the button nothing happens.
Actually I now have two buttons on the page, one using the <a href>
tag and the other uses an ng-click="viewServiceTickets()"
and in the viewServiceTickets() function I use the $location.path('serviceList');
(also tried '/serviceList' and '#/serviceList' as some people have been suggesting) but to no avail.
If I run it:
- In the preview mode - it works
- In the mobile browser simulator - it works
- In the iOS simulator - it works
- On an iOS device - IT FAILS (i.e. when I press either the button or the
<a href
, nothing happens and I see no errors in the log.
My angular config looks like this
var serviceApp = angular.module('serviceApp', ['ngRoute', 'ngTouch']);
var serviceControllers = {};
serviceApp.controller(serviceControllers);
serviceApp.config(function ($compileProvider){
$compileProvider.aHrefSanitizationWhitelist(/^\s*(https?|ftp|mailto|file|tel):/);
});
//This configures the routes and associates each route with a view and a controller
serviceApp.config(function ($routeProvider) {
$routeProvider
.when('/',
{
controller: 'HomePageController',
templateUrl: 'views/HomePage/homePage.html'
})
.when('/serviceList',
{
controller: 'ServiceTicketListController',
templateUrl: 'views/ServiceTicketList/serviceTicketList.html'
})
.otherwise({ redirectTo: '/' });
});
And my main.js file has
function wlCommonInit(){
document.addEventListener("deviceready", onDeviceReady, true);
}
function onDeviceReady() {
angular.bootstrap(document);
}
The home page is very simple
<div id="splashPage">
<div>
<h2>Service Ticket Viewer</h2>
<button type="button" data-ng-click="viewServiceTickets()">View Service Tickets</button>
<div class="mainBtnContainer">
<a href="#/serviceList" >
<img src="images/technical-support.png">
</a>
</div>
</div>
</div>
And finally my controller is
serviceControllers.HomePageController = function ($scope, $location, $window, TicketService) {
$scope.currentServiceTicket = {};
init();
function init() {
console.log("Initialisation of HomePageController complete");
}
$scope.viewServiceTickets = function() {
//$locationProvider.html5Mode(true);
$location.path("/serviceList");
};
$scope.goBack = function() {
console.log("Going Back");
$window.history.back();
};
};
I've looked and tried a number of suggestions already which don't appear to work for me:
- Angular ng-view/routing not working in PhoneGap
- angular.js doesn't work ng-view tag in PhoneGap
- angular ng-view phonegap is not working
I forgot to add my main index.html page. All page fragments are injected into the div with the data-ng-view directive.
<!DOCTYPE HTML>
<html data-ng-app="serviceApp">
<head>
<meta charset="UTF-8">
<title>index</title>
<meta name="viewport"
content="width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, user-scalable=0">
<meta name="format-detection" content="telephone=no">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="black">
<link rel="shortcut icon" href="images/favicon.png">
<link rel="apple-touch-icon" href="images/apple-touch-icon.png">
<link rel="stylesheet" href="css/main.css">
<script>window.$ = window.jQuery = WLJQ;</script>
<script src="js/angularjs/angular.js"></script>
<script src="js/angularjs/angular-touch.js"></script>
<script src="js/angularjs/angular-route.js"></script>
<script src="js/angularjs/angular-animate.js"></script>
</head>
<body style="display: none;">
<div>
<div data-ng-view=""></div>
</div>
<script src="js/initOptions.js"></script>
<script src="js/main.js"></script>
<script src="js/messages.js"></script>
<script src="js/router.js"></script>
<!-- Controllers -->
<script src="views/HomePage/homePageController.js"></script>
<script src="views/ServiceTicketList/serviceTicketListController.js"></script>
<script src="views/ServiceTicketDetails/serviceTicketDetailsController.js"></script>
<!-- Services -->
<script src="js/models/serviceTickets.js"></script>
</body>
</html>
I'm running in Worklight Studio 6.1 and angularjs 1.2.13
Any ideas? I'm sure (hoping) it's something silly that I've done/haven't done.