Skip to content

Commit cebdbfd

Browse files
committed
Remove upload methods from the scope when the widget is removed. Fixes blueimp#2258.
1 parent 377652a commit cebdbfd

File tree

1 file changed

+35
-22
lines changed

1 file changed

+35
-22
lines changed

js/jquery.fileupload-angular.js

Lines changed: 35 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* jQuery File Upload AngularJS Plugin 1.2
2+
* jQuery File Upload AngularJS Plugin 1.2.1
33
* https://github.com/blueimp/jQuery-File-Upload
44
*
55
* Copyright 2013, Sebastian Tschan
@@ -170,6 +170,29 @@
170170
.controller('FileUploadController', [
171171
'$scope', '$element', '$attrs', 'fileUpload',
172172
function ($scope, $element, $attrs, fileUpload) {
173+
var uploadMethods = {
174+
progress: function () {
175+
return $element.fileupload('progress');
176+
},
177+
active: function () {
178+
return $element.fileupload('active');
179+
},
180+
option: function (option, data) {
181+
return $element.fileupload('option', option, data);
182+
},
183+
add: function (data) {
184+
return $element.fileupload('add', data);
185+
},
186+
send: function (data) {
187+
return $element.fileupload('send', data);
188+
},
189+
process: function (data) {
190+
return $element.fileupload('process', data);
191+
},
192+
processing: function (data) {
193+
return $element.fileupload('processing', data);
194+
}
195+
};
173196
$scope.disabled = angular.element('<input type="file">')
174197
.prop('disabled');
175198
$scope.queue = $scope.queue || [];
@@ -202,27 +225,6 @@
202225
}
203226
}
204227
};
205-
$scope.progress = function () {
206-
return $element.fileupload('progress');
207-
};
208-
$scope.active = function () {
209-
return $element.fileupload('active');
210-
};
211-
$scope.option = function (option, data) {
212-
return $element.fileupload('option', option, data);
213-
};
214-
$scope.add = function (data) {
215-
return $element.fileupload('add', data);
216-
};
217-
$scope.send = function (data) {
218-
return $element.fileupload('send', data);
219-
};
220-
$scope.process = function (data) {
221-
return $element.fileupload('process', data);
222-
};
223-
$scope.processing = function (data) {
224-
return $element.fileupload('processing', data);
225-
};
226228
$scope.applyOnQueue = function (method) {
227229
var list = this.queue.slice(0),
228230
i,
@@ -240,6 +242,8 @@
240242
$scope.cancel = function () {
241243
this.applyOnQueue('$cancel');
242244
};
245+
// Add upload methods to the scope:
246+
angular.extend($scope, uploadMethods);
243247
// The fileupload widget will initialize with
244248
// the options provided via "data-"-parameters,
245249
// as well as those given via options object:
@@ -277,6 +281,15 @@
277281
'fileuploadprocessstop'
278282
].join(' '), function (e, data) {
279283
$scope.$emit(e.type, data);
284+
}).on('remove', function () {
285+
// Remove upload methods from the scope,
286+
// when the widget is removed:
287+
var method;
288+
for (method in uploadMethods) {
289+
if (uploadMethods.hasOwnProperty(method)) {
290+
delete $scope[method];
291+
}
292+
}
280293
});
281294
// Observe option changes:
282295
$scope.$watch(

0 commit comments

Comments
 (0)