Skip to content

Commit

Permalink
Merge pull request #77 from mmbfreitas/master
Browse files Browse the repository at this point in the history
Fix clean after load
  • Loading branch information
adonespitogo committed Oct 30, 2016
2 parents 04bf325 + c23ab67 commit ea75a29
Showing 1 changed file with 27 additions and 14 deletions.
41 changes: 27 additions & 14 deletions src/angular-base64-upload.js
Expand Up @@ -90,21 +90,31 @@

function _onChange(e) {
if (attrs.onChange) {
scope.onChange()(e, rawFiles);
if (scope.onChange && typeof scope.onChange() === "function") {
scope.onChange()(e, rawFiles);
}
else {
scope.onChange(e, rawFiles);
}
}
}

function _onAfterValidate(e) {
if (attrs.onAfterValidate) {
// wait for all promises, in rawFiles,
// then call onAfterValidate
var promises = [];
for (var i = rawFiles.length - 1; i >= 0; i--) {
promises.push(rawFiles[i].deferredObj.promise);
}
$q.all(promises).then(function() {
scope.onAfterValidate()(e, fileObjects, rawFiles);
});
// wait for all promises, in rawFiles,
// then call onAfterValidate
var promises = [];
for (var i = rawFiles.length - 1; i >= 0; i--) {
promises.push(rawFiles[i].deferredObj.promise);
}
$q.all(promises).then(function () {
if (scope.onAfterValidate && typeof scope.onAfterValidate() === "function"){
scope.onAfterValidate()(e, fileObjects, rawFiles);
}
else{
scope.onAfterValidate(e, fileObjects, rawFiles);
}
});
}
}

Expand Down Expand Up @@ -155,7 +165,12 @@
});

if (attrs.onload) {
scope.onload()(e, fReader, file, rawFiles, fileObjects, fileObject);
if (scope.onload && typeof scope.onload() === "function"){
scope.onload()(e, fReader, file, rawFiles, fileObjects, fileObject);
}
else{
scope.onload(e, rawFiles);
}
}

};
Expand Down Expand Up @@ -183,9 +198,7 @@

scope.$watch(function() {
return ngModel.$viewValue;
}, function(val, oldVal) {
if (ngModel.$isEmpty(oldVal)) {
return; }
}, function(val) {
if (ngModel.$isEmpty(val)) {
scope._clearInput();
}
Expand Down

0 comments on commit ea75a29

Please sign in to comment.