Skip to content

Instantly share code, notes, and snippets.

@StasKoval
Created September 19, 2013 12:03
Show Gist options
  • Save StasKoval/6622427 to your computer and use it in GitHub Desktop.
Save StasKoval/6622427 to your computer and use it in GitHub Desktop.
ngular.module("uploaderComponent", []).directive("fileupload", function() {
return {
restrict: "A",
scope: {
done: "&",
progress: "&",
fail: "&",
uploadurl: "="
},
link: function(scope, elem, attrs) {
var uploadOptions;
uploadOptions = {
url: scope.uploadurl({
dataType: "json"
})
};
if (scope.done) {
uploadOptions.done = function(e, data) {
return scope.$apply(function() {
return scope.done({
e: e,
data: data
});
});
};
}
if (scope.fail) {
uploadOptions.fail = function(e, data) {
return scope.$apply(function() {
return scope.fail({
e: e,
data: data
});
});
};
}
if (scope.progress) {
uploadOptions.progress = function(e, data) {
return scope.$apply(function() {
return scope.progress({
e: e,
data: data
});
});
};
}
return elem.fileupload(uploadOptions);
}
};
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment