Skip to content

Instantly share code, notes, and snippets.

@mandado
Last active September 3, 2015 16:55
Show Gist options
  • Select an option

  • Save mandado/0825fc5ed700e40b8d80 to your computer and use it in GitHub Desktop.

Select an option

Save mandado/0825fc5ed700e40b8d80 to your computer and use it in GitHub Desktop.
(function (module) {
'use strict';
module.directive('upload', ['$http', function ($http) {
var htmlTemplate = [
'<div>',
'<input type="file" name="{{inputName}}">',
'<a class="btn btn-primary btn-sm" target="_blank" ng-href="{{downloadLink}}" ng-if="hasDownloadLink">{{title_button}}</a>',
'</div>'
].join('');
return {
restrict: 'E',
scope: {
downloadLink: '=',
inputName: '@',
urlServer: '@'
},
template: htmlTemplate,
link: function (scope, el) {
if (scope.inputName === undefined) {
scope.inputName = 'upload';
}
if (scope.title_button === undefined) {
scope.title_button = 'Baixar arquivo';
}
scope.hasDownloadLink = !scope.linkDownload;
el.on('change', function () {
$http({
url : scope.urlServer,
})
});
}
}
}]);
})(angular.module('upload-directive', []));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment