我有使用angular-file-upload插件上传照片的AngularJS 1.0.7代码:
HTML:
<div ng-hide="user.mainPhoto" style="margin-top: 20px">
<center>
<div ng-controller="FileUploadCtrl">
<button class="btn btn-success btn-primary" ng-click="clickFileInput('addMainPhoto')"><i class="fa-icon-picture" style="vertical-align: middle"></i> {{'ADD_PROFILE_PHOTO' | translate}}</button>
</div>
</center>
<input id="addMainPhoto" type="file" ng-file-select="onFileSelect($files, 'user', user.id)" class="hidden" accept="image/*">
</div>
控制器:
.controller('FileUploadCtrl', function ($scope, $upload, growl, API_SERVER_URL, ngProgress, PhotoService) {
$scope.clickFileInput = function(id){
$('#' + id).trigger('click');
};
$scope.onFileSelect = function($files, entity, id, action) {
//$files: an array of files selected, each file has name, size, and type.
console.log("BoatPhotoUploadCtrl-->entity:" + entity + "; id:" + id);
...
当我点击上传按钮时,我收到下一个错误:
Error: $apply already in progress
at Error (native)
at beginPhase (http://localhost/lib/angular/angular.js:8334:40)
at Object.$get.Scope.$digest (http://localhost/lib/angular/angular.js:7913:9)
at HTMLDocument.link.T (http://localhost/lib/bootstrap/ui-bootstrap-tpls-0.6.0.min.js:1565:34)
at HTMLDocument.x.event.dispatch (http://code.jquery.com/jquery-1.10.2.min.js:5:14129)
at HTMLDocument.x.event.add.v.handle (http://code.jquery.com/jquery-1.10.2.min.js:5:10873)
at Object.x.event.trigger (http://code.jquery.com/jquery-1.10.2.min.js:5:13255)
at HTMLInputElement.<anonymous> (http://code.jquery.com/jquery-1.10.2.min.js:5:20776)
at Function.x.extend.each (http://code.jquery.com/jquery-1.10.2.min.js:4:5347)
at x.fn.x.each (http://code.jquery.com/jquery-1.10.2.min.js:4:1999)
我自己并没有使用$ apply,这很奇怪,因为我使用相同的插件在应用程序的其他部分上传照片并且工作正常。
答案 0 :(得分:0)
$('#' + id).trigger('click'); - this line causes an error