本文介绍了我怎么能告诉AngularJS到"刷新"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这种情况我自定义指令范围之外的click事件,所以不是使用属性,我使用的是jQuery.click()监听器,并呼吁像这样我的范围内的功能NG单击:

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()方法是一个简单的功能,看起来像这样:

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

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

在我看来,我有NG-秀必将isOpen会像这样的元素:

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

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

在调试时,我发现,关闭()被调用,isOpen会被更新为假,但AngularJS观点并没有更新。有没有一种方法,我可以手动告诉角度更新视图?还是有更多的角的方式来解决这个问题,我没有看到?

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?

推荐答案

解决的办法是打电话...

The solution was to call...

$scope.$apply();

......在我的jQuery的事件回调。

...in my jQuery event callback.

这篇关于我怎么能告诉AngularJS到&QUOT;刷新&QUOT;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-16 01:23