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.

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.