I try to use angular.js with PhoneGap.It works fine at chrome browser.But it doesn't work
at ng-view tag.And angular module doesn't called when I run it on the simulator. Do you have any idea?
My code is like this.
<body>
<div class="app" >
<h1>Welcome!</h1>
<div id="deviceready">
<div ng-view></div>
</div>
</div>
<script type="text/javascript" src="cordova-2.0.0.js"></script>
<script type="text/javascript" src="js/index.js"></script>
<script type="text/javascript">
app.initialize();
</script>
<script src="http:////cdnjs.cloudflare.com/ajax/libs/zepto/1.0rc1/zepto.min.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.0.2/angular.min.js"> </script>
<script type="text/javascript" src="js/router.js"></script>
</body>
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');
},
report: function(id) {
console.log("report:" + id);
// hide the .pending <p> and show the .complete <p>
document.querySelector('#' + id + ' .pending').className += ' hide';
var completeElem = document.querySelector('#' + id + ' .complete');
completeElem.className = completeElem.className.split('hide').join('');
}
};
angular.module("app",[]).
config(["$routeProvider",function($routeProvider){
$routeProvider.when("/",{templateUrl:"templates/home.html"});
}]);
Try the bootstrap api method to manually start the app on deviceReady. something like:
function onDeviceReady() {
...
angular.bootstrap(document, ['ngView']);
...
}
document.addEventListener("deviceready", onDeviceReady, true);
http://docs.angularjs.org/api/angular.bootstrap
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