Angular JS views not updating properly

孤人 提交于 2019-12-03 05:02:31

As the docs explains:

$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.

So if you have a jQuery code like

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

You have to tell angular Js something has changed with $scope.$apply().

Here is a nice blog on why: http://www.yearofmoo.com/2012/10/more-angularjs-magic-to-supercharge-your-webapp.html#apply-digest-and-phase

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!