Angularjs 在触发phonegap deviceready事件后设置$rootScope变量
在触发deviceready事件后,有没有办法在我的angular应用程序中设置$rootScope变量Angularjs 在触发phonegap deviceready事件后设置$rootScope变量,angularjs,cordova,Angularjs,Cordova,在触发deviceready事件后,有没有办法在我的angular应用程序中设置$rootScope变量 var application = { // Application Constructor initialize: function() { this.bindEvents(); }, // Bind any events that are required on startup. Common events are: // 'load', 'deviceready', 'off
var application = {
// Application Constructor
initialize: function() {
this.bindEvents();
},
// Bind any events that are required on startup. Common events are:
// 'load', 'deviceready', 'offline', and 'online'.
bindEvents: function() {
document.addEventListener('deviceready', this.onDeviceReady, true);
},
// deviceready Event Handler
onDeviceReady: function() {
//set angular app $rootScope variable
}
}) 要在DeviceRady事件处理程序的$rootScope中设置属性,请确保将其包装在$apply方法调用中,因为DeviceRady事件发生在AngularJS之外。以下是一个例子:
angular.module('myapp').run(['$rootScope', function($rootScope) {
document.addEventListener('deviceready', function() {
$rootScope.$apply(function() {
$rootScope.myVariable = "variable value";
});
});
});
你要写在哪里?我在index.js文件中有我的onDeviceReady事件,我在main.js中创建了angular应用程序模块。我应该在那之后复制这个吗?