Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/22.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和监听窗口事件/消息_Angularjs - Fatal编程技术网

AngularJS和监听窗口事件/消息

AngularJS和监听窗口事件/消息,angularjs,Angularjs,我试图从窗口事件触发AngularJS控制器函数。但是,函数中的$http()不会执行。它只是停止了 window.addEventListener("message", function(msg) { // this works!! alert(angular.element(document.getElementById('ListFindRooms')).scope().var); // this kinda works, but Angular $http()

我试图从窗口事件触发AngularJS控制器函数。但是,函数中的$http()不会执行。它只是停止了

window.addEventListener("message", function(msg) {

    // this works!!
    alert(angular.element(document.getElementById('ListFindRooms')).scope().var);

    // this kinda works, but Angular $http() inside the funciton is not executed
    angular.element(document.getElementById('ListFindRooms')).scope().function();
}

}); 

我希望函数的名称不是真正的
function
,因为这是一个关键字……您是否尝试过提取作用域并在
作用域中调用函数。$apply
block?@Praveenram,您能解释一下您的意思吗?我是Angular的新手。您可以尝试
var element\u scope=Angular.element(document.getElementById('ListFindRooms')).scope();element_scope.$apply(函数(){element_scope.function_name();})。它在$apply$digest循环下运行角度方法。此处链接到范围文档: