[英]angularjs: view data doesn't update after async call
I am using a 3rd party js library to make http requests to their api. 我正在使用第三方js库向其api发出http请求。 I perform this operation on every keystroke in an input field using "ng-keyup".
我使用“ ng-keyup”对输入字段中的每个击键执行此操作。 After the call to there api returns I set the $scope.results which populates the view.
在对api的调用返回之后,我设置了$ scope.results来填充视图。 However the view always updates one iteration behind, debugging this looks to be with the async call.
但是,视图总是在后面更新一次迭代,调试似乎是通过异步调用进行的。
Is there a way to refresh the view or make the async call differently rather than just a callback? 有没有一种方法可以刷新视图或以不同的方式进行异步调用,而不仅仅是回调?
Looks like your callback might be executing outside of angular context. 看起来您的回调可能在角度上下文之外执行。 Try calling
$scope.$apply()
in async callback. 尝试在异步回调中调用
$scope.$apply()
。 If that's not the issue, post some code please :) 如果这不是问题,请发布一些代码:)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.