Dustin Dustin - 4 months ago 9
AngularJS Question

How can I tell AngularJS to "refresh"

I have a click event that happens outside the scope of my custom directive, so instead of using the "ng-click" attribute, I am using a jQuery.click() listener and calling a function inside my scope like so:

$('html').click(function(e) {
scope.close();
);


close() is a simple function that looks like this:

scope.close = function() {
scope.isOpen = false;
}


In my view, I have an element with "ng-show" bound to isOpen like this:

<div ng-show="isOpen">My Div</div>


When debugging, I am finding that close() is being called, isOpen is being updated to false, but the AngularJS view is not updating. Is there a way I can manually tell Angular to update the view? Or is there a more "Angular" approach to solving this problem that I am not seeing?

Answer

The solution was to call...

$scope.$apply();

...in my jQuery event callback.

Comments