Skip to content

Instantly share code, notes, and snippets.

@ahmad-moussawi
Created June 16, 2014 10:32
Show Gist options
  • Save ahmad-moussawi/727a3eac97851327eb87 to your computer and use it in GitHub Desktop.
Save ahmad-moussawi/727a3eac97851327eb87 to your computer and use it in GitHub Desktop.
angular dropzone uploader
<div ng-show="!item.edit">
<div ng-if="item.row.logo" >
<img ng-src="uploads/mdpi/{{item.row.logo}}" style="max-width: 80px;"/>
</div>
<div ng-if="!item.row.logo"><i>No image selected</i></div>
</div>
<div class="dropzone">
<upload ng-show="!item.row.logo" ng-model="item.row.logo">Drop image here</upload>
<div ng-if="item.row.logo" >
<img ng-src="uploads/mdpi/{{item.row.logo}}" style="max-width: 80px;"/>
<button class="btn btn-xs btn-danger" type="button" ng-click="removeImage(item)" >Remove</button>
</div>
</div>
<script>
app.directive('upload', ['$http', function($http) {
return {
require: 'ngModel',
restrict: 'E',
link: function(scope, elm, attrs, ctrl) {
var instance = new Dropzone(elm[0], {
url: 'api/uploader/image',
maxFilesize: 1,
paramName: 'image',
addRemoveLinks: true,
maxFiles: 1
});
instance.on('success', function(file, response) {
ctrl.$setViewValue(response.path);
console.log(response);
scope.$apply();
});
instance.on('removedfile', function(file) {
if (ctrl.$viewValue && typeof ctrl.$viewValue.path === 'string') {
$http.post('api/uploader/remove', {file: ctrl.$viewValue});
}
});
}
};
}]);
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment