Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angularjs 在触发phonegap deviceready事件后设置$rootScope变量_Angularjs_Cordova - Fatal编程技术网

Angularjs 在触发phonegap deviceready事件后设置$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

在触发deviceready事件后,有没有办法在我的angular应用程序中设置$rootScope变量

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应用程序模块。我应该在那之后复制这个吗?