Angular JS视图无法正确更新 [英] Angular JS views not updating properly

查看:87
本文介绍了Angular JS视图无法正确更新的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要执行以下操作

ng单击,这反过来又调用了显示jQuery Qtip -> 的jQuery ajax strong>在Qtip弹出窗口中,我对元素->进行了 ng单击,该元素执行了 $ http发布,并具有一些回调以更新$ scope值.

ng-click in my view -> which inturn calls a jQuery ajax function that displays jQuery Qtip -> In the Qtip popup I have an ng-click on an element -> which performs a $http post and has some callbacks to update $scope values.

所有这些事情都在正常发生.但是,根据最后阶段在回调中所做的更改,更新不会反映在视图中.

So all these things are happening properly. But the updates are not getting reflected in the view as per the changes made in the callback in the final stage.

我认为我有一个用于"ng-mousemove"的功能.因此,每当我移动鼠标时,视图中的更新就会反映出来.

I have a function for "ng-mousemove" in my view. So whenever I move my mouse, the updates in the view are getting reflected.

我在这里做错了什么?是因为在角度和非角度之间转换吗?谁能帮我解决这个问题?

What am I doing wrong here? Is the because of transitioning between angular and non-angular? Can anyone help me how to solve this?

推荐答案

作为文档解释:

$ apply()用于从外部执行有角度的表达式 角度框架. (例如,从浏览器DOM事件中, setTimeout,XHR或第三方库).因为我们正在呼吁 我们需要执行适当的范围生命周期的角度框架 异常处理,执行监视.

$apply() is used to execute an expression in angular from outside of the angular framework. (For example from browser DOM events, setTimeout, XHR or third party libraries). Because we are calling into the angular framework we need to perform proper scope life-cycle of exception handling, executing watches.

因此,如果您有 jQuery代码,例如

$('#myDiv').on('click', function() {
  // do stuff
  $scope.$apply();
});

这篇关于Angular JS视图无法正确更新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆