下面是我的 View 的代码和我的 Controller 中的代码摘要。
查看:
<div id="search_results" ng-controller="SearchCtrl">
<ul>
<li ng-repeat="result in results">{{result.name}}</li>
</ul>
</div>
Controller :
myapp.controller('SearchCtrl', function($scope,SearchF) {
$scope.launch_search = function() {
SearchF.update(function() {
$scope.results = SearchF.get();
});
}
})
函数 .get() 返回我的数据,但 View 不更新。看起来我的范围($scope.results)并不是指一般范围。如果我在 launch_search 函数之外编写 .update() block ,则 View 会正常更新。
有什么想法吗?
非常感谢大家
最佳答案
.get()
是一个异步调用,如果使用 ngResource
,则在回调中分配数据:
SearchF.get({}, function(data) {
$scope.results = data;
});
关于javascript - Controller 中 AngularJS 范围的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23659548/