Using reactive form validation with <input type=“file”> for an Angular app

前端 未结 3 1657
梦如初夏
梦如初夏 2020-12-30 03:46

I\'m writing a component with a file picker that uploads a file to our CDN. I\'m trying to add a reactive form on this component to validate the image input, so I can check

3条回答
  •  既然无缘
    2020-12-30 04:19

    export class myClass implements OnInit {
    
      myForm = new FormGroup({
        name: new FormControl(''),
        myFile: new FormControl('')
      })
    
      onFileChange($event) {
    
        this.myForm.patchValue({
          myFile: $event.target.files[0]
        })
      }
    
    }

提交回复
热议问题