javascript - Input type="file" show error when i upload a image file -


when try upload image file type input angular validation shows error , won't passes

<input type="file" name="displaypic" ng-model="displaypic" ng-pattern="/\.(jpe?g|png|gif|bmp)$/i" ng-required="true" /> <span ng-show="signupform.displaypic.$error.pattern">* must image</span>   

with css input.ng-invalid.ng-touched{border: 2px solid red;}

its not show error of $error.pattern css invalid file , didn't let form submit

you have use directive create object in controller

$scope.file={}; $scope.file.filedetail={};  <input type="file" fileupload filetoread="file.filedetail" />  .directive("fileupload ", [function () { return {     scope: {         filetoread: "="     },     link: function (scope, element, attributes) {         element.bind("change", function (changeevent) {             var reader = new filereader();             reader.onload = function (loadevent) {                 scope.$apply(function () {                     scope.filetoread= loadevent.target.result;                 });             }             reader.readasdataurl(changeevent.target.files[0]);         });     } }  }]); 

Comments

Popular posts from this blog

Is there a better way to structure post methods in Class Based Views -

performance - Why is XCHG reg, reg a 3 micro-op instruction on modern Intel architectures? -

jquery - Responsive Navbar with Sub Navbar -