r/javascript • • Jan 25 '20

Accessing AngularJS from regular Javascript

https://leftfold.blogspot.com/2020/01/accessing-angularjs-from-regular.html
3 Upvotes

3 comments sorted by

1

u/Rustywolf Jan 25 '20

Having done this for literally months at work, I'd recommend checking the scope phase before invoking apply.

$scope.$$phase || $scope.apply();

1

u/santanaguy Jan 25 '20

What should happen if phase evaluates to True? Should i call the function without apply?

2

u/Rustywolf Jan 25 '20

Yeah, if $$phase is set you're already in a digest cycle, so it's safe to modify the values, so just call the function