Last active
September 3, 2015 16:55
-
-
Save mandado/0825fc5ed700e40b8d80 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| (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