ng-model for `<input type=“file”/>` (with directive DEMO)

后端 未结 12 2285
北恋
北恋 2020-11-21 06:40

I tried to use ng-model on input tag with type file:


But after selecting a file, in

12条回答
  •  醉梦人生
    2020-11-21 07:08

    function filesModelDirective(){
      return {
        controller: function($parse, $element, $attrs, $scope){
          var exp = $parse($attrs.filesModel);
          $element.on('change', function(){
            exp.assign($scope, this.files[0]);
            $scope.$apply();
          });
        }
      };
    }
    app.directive('filesModel', filesModelDirective);
    

提交回复
热议问题