How to use input type file in angular material

后端 未结 4 1225
萌比男神i
萌比男神i 2021-02-01 02:50

How to use input type file in angular material

Hi, I am using angular material for designing. when i go on angular material site there no input type fil

4条回答
  •  有刺的猬
    2021-02-01 03:19

    If you dont want to use some strange workaround, then just dont place input into the mat-form-field. You can place it outside the mat-form-field but still include the value into the FormGroup. Check the example

    import { FormBuilder, FormGroup, Validators } from '@angular/forms'; someForm: FormGroup; constructor(private formBuilder: FormBuilder) {} ngOnInit(): void { this.someForm = this.formBuilder.group({ someFCN: [{ value:'', disabled: false },Validators.required], file: { value:'', disabled: false } }); } onChange(event: Event) { /*not sure what you want to do with file, i'll just set selected file´s name as value, but obviously u can do much more than just get file´s name.*/ this.someForm.controls['file'].setValue(event.target.files[0].name); } onSubmit() { return this.someForm.getRawValue(); }

提交回复
热议问题