AngularJS使用ng-repeat不更细View

今天在使用angularJS开发一个上传图片的功能,但是遇到了view不更新的问题,查了国内大部分网站,发现很多人都出现过这个问题,但是他们一般都是出现在请求数据中,我的项目全部都是使用promise对象处理的,所以没有出现过他们出现的问题,但是上传图片是没有数据传输的(因为我意图是在本地裁剪图片);

如果有像我这样子的,可以使用:

$scope.$apply();
通知视图更新,但是这不是一个好的习惯。

原文:
$scope.$apply(function() {
  $scope.msgs = newMsgs;
});

That is telling Angular that you’ve modified something it needs to know about from a context that it doesn’t know about (the jQuery ajax call in this case).

There are some valid uses of $scope.$apply(), such as in event handlers, but most other times it is a sign of bad practices. You should definitely be using Angular’s $http for ajax calls.

 

 

 

Leave a Comment

 
Copyright © 2008-2021 lanxinbase.com Rights Reserved. | 粤ICP备14086738号-3 |