File Upload with Angular Material

后端 未结 12 1093
抹茶落季
抹茶落季 2021-01-30 15:48

I\'m writing an web app with AngularJS and angular-material. The problem is that there\'s no built-in component for file input in angular-material. (I feel that file uploading d

12条回答
  •  春和景丽
    2021-01-30 16:36

    Another example of the solution. Will look like the following

    CodePen link there.

      
        
        
          
          
    Select your file
    attach_file
    .directive('chooseFile', function() { return { link: function (scope, elem, attrs) { var button = elem.find('button'); var input = angular.element(elem[0].querySelector('input#fileInput')); button.bind('click', function() { input[0].click(); }); input.bind('change', function(e) { scope.$apply(function() { var files = e.target.files; if (files[0]) { scope.fileName = files[0].name; } else { scope.fileName = null; } }); }); } }; });

    Hope it helps!

提交回复
热议问题