简体   繁体   English

无法访问在 Electron ipcRenderer 中实现的 Angular $scope 变量

[英]Cannot access Angular $scope variable implemented inside Electron ipcRenderer

I'm trying to access a $scope variable from the ipcRenderer implemented under an angular controller like this我正在尝试从像这样的角度控制器下实现的 ipcRenderer 访问 $scope 变量

angular
        .module('app',[])
        .controller('inputsController',function ($scope){

            var ipcRenderer = require("electron").ipcRenderer;
                ipcRenderer.on('my-Response',function(event,data){
                    $scope.inputs = data;
                });
                $scope.test = 'some value';
                console.log('test value : ' + $scope.test); //prints some valuee
                console.log('inputs value : ' + $scope.inputs);// undefined
        });

In the html page I'm trying to access the $scope data like this:在 html 页面中,我试图像这样访问 $scope 数据:

<body ng-app="app">
    <div ng-controller="inputsController" class="container">
        test: {{test}}
        inputs: {{inputs}}
    </div>
</body>

The log results shows that the value of $scope.inputs is undefined, therefore the value is not bound in the page.日志结果显示$scope.inputs的值未定义,因此该值未绑定到页面中。

My initial thought was that since we have the $scope available from the controller(being injected as a parameter), we should be able to use it to attached values like $scope.input and then get it bound in the page.However this doesnt seem to behave as expected.我最初的想法是,由于我们有控制器提供的 $scope(作为参数注入),我们应该能够将它用于附加值,如 $scope.input,然后将其绑定到页面中。但是这并没有似乎表现得如预期。

Is there anything that I am missing here or my approach of having ipc inside an angular controller is wrong ?有什么我在这里遗漏的吗,或者我在角度控制器中使用 ipc 的方法是错误的? please suggest ....请建议....

the event field is outside of angular's scope, you can do like this:事件字段在 angular 的范围之外,您可以这样做:

var ipcRenderer = require("electron").ipcRenderer;
            ipcRenderer.on('my-Response',function(event,data){
                $timeout(function(){
                     $scope.inputs = data;
                }, 0);
            });

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM