ngf-max-size $digest() error with ng-file-upload in angular.js

前端 未结 1 396
陌清茗
陌清茗 2021-01-26 04:22

This is source code.

相关标签:
1条回答
  • 2021-01-26 04:58

    You shouldn't change your model inside watch since it creates a loop. If you just need to alert when a file is uploaded whether the size is above you can just check the status.

    Let's say you have this input:

     <input type="file" ngf-select ng-model="picFile" name="file"    
             accept="image/*" ngf-max-size="1MB" required
             ngf-model-invalid="errorFile">
    

    Then you just need to have this in your html to show the limit size exceeded alert:

    <i ng-show="myForm.file.$error.maxSize">File too large 
          {{errorFile.size / 1000000|number:1}}MB: max 1M</i>
    

    And also you don't need a directive to handle that.

    Check here for more info around validation.

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