Reputation: 43501
My index.html
is:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta name="format-detection" content="telephone=no" />
<meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width, height=device-height" />
<link rel="stylesheet" type="text/css" href="css/index.css" />
<title>Hello World</title>
</head>
<body ng-app="app">
THIS WORKS NOW!
<div ng-view></div>
<script type="text/javascript" src="cordova.js"></script>
<script type="text/javascript" src="js/angular.min.js"></script>
<script type="text/javascript" src="js/angular-route.min.js"></script>
<script type="text/javascript" src="js/app.js"></script>
</body>
</html>
And in app.js
, I have:
var app = angular.module('app', ['ngRoute']);
app.config(['$routeProvider', '$locationProvider', function($routeProvider, $locationProvider) {
$routeProvider.when('/', {
templateUrl: 'templates/home.html'
}).when('/dashboard', {
templateUrl: '/templates/dashboard.html'
}).otherwise({
redirectTo: '/'
});
$locationProvider.html5Mode(true);
}
]);
So I run cordova build ios
and it does it's magic to make an xcode project, which I then open and run. I see THIS WORKS NOW!
, but I don't see the contents of my home.html
file.
What am I doing wrong?
Upvotes: 3
Views: 1337
Reputation: 1485
You need bootstrap angular:
app.js
is fine!
but remove ng-app
inside the tag <body>
and start angular when the event onDeviceReady
has been triggered :
index.js
file:
var app = {
initialize: function () {
this.bindEvents();
},
bindEvents: function () {
document.addEventListener("deviceready", this.onDeviceReady, false);
},
onDeviceReady: function () {
angular.element(document).ready(function () {
angular.bootstrap(document, ["app"]);
});
}
};
normally that is all you need to do.
Upvotes: 5