Validation doesnt work for File Input with 'Required' attribute- AngularJS

前端 未结 1 1474
轮回少年
轮回少年 2021-01-12 10:04

I have been playing around this and couldnt get it to work. I was creating an angular form and I was able to get the validation to work when required attribute

相关标签:
1条回答
  • 2021-01-12 10:44

    ngModelController doesn't currently support input type=file.

    you can solve your issue with a custom directive.

    app.directive('validFile',function(){
      return {
        require:'ngModel',
        link:function(scope,el,attrs,ngModel){
          el.bind('change',function(){
            scope.$apply(function(){
              ngModel.$setViewValue(el.val());
              ngModel.$render();
            });
          });
        }
      }
    });
    

    see usage here

    0 讨论(0)
提交回复
热议问题