0

I want to make an application with node-webkit using AngularJS. No problem so far but when I want Angular to watch over a "legacy variable" by using the method described in this answer I just get an Error: [$rootScope:inprog].

I wrapped my node.js function into $scope.$apply() like this:

$scope.$apply(myNodeModule("test", function(err, res) {
        if (err) {return console.log(err)}
        myLegacyVar = res;
}));

And watching over the (global) myLegacyVar variable like described in the answer mentioned before:

function () {
            return $window.myLegacyVar
        }, function(n,o){
            console.log("changed ",n);
            $scope.data = n;
        }
);

All of the code resides within my Angular controller function.

The function is async, so I guess it could have to do with that? Or is this function inception I have going on in $apply maybe causing my error?

I'm just clueless right now, I have just recently started using AngularJS, hours of googleing haven't gotten my very far.

Community
  • 1
  • 1
timonsku
  • 1,249
  • 2
  • 21
  • 45

1 Answers1

0

This answer helped. The safe $apply function there did the trick. I added that function to my controller and added this snipped to my node.js function:

var scope = angular.element($("#angularDOMElement")).scope();
scope.safeApply(function(){
    myLegacyVar = res;
})

I don't know if thats the proper way to do it but its working.

Community
  • 1
  • 1
timonsku
  • 1,249
  • 2
  • 21
  • 45