File pick with Angular JS

后端 未结 8 772
时光取名叫无心
时光取名叫无心 2020-12-08 07:50

I would like to pick up a file with AngularJS:

HTML:

8条回答
  •  猫巷女王i
    2020-12-08 08:10

    Directive that uses the ng-model-controller:

    app.directive("selectNgFiles", function() {
      return {
        require: "ngModel",
        link: function postLink(scope,elem,attrs,ngModel) {
          elem.on("change", function(e) {
            var files = elem[0].files;
            ngModel.$setViewValue(files);
          })
        }
      }
    });
    

    Usage:

    
    

    For more information, see Working Demo of Directive that Works with ng-model.

提交回复
热议问题