Angular2 - 如何将窗体上的“touch”属性设置为true

时间:2017-02-22 18:27:40

标签: forms angular angular2-forms reactive-forms

我的组件中有一个被动表单,我想在每个输入上设置set /A "COUNT=0" for /F "delims=" %%F in (' rem/ // List files that would be copied without `/L`; remove summary line: ^& ^ cd /D "C:\test1" ^&^& xcopy /L /R /D /I /S /Y "." "C:\test2" ^| find ".\" ') do ( rem // Check file extension of each file: if /I not "%%~xF"==".txt" if /I not "%~xF"==".exe" ( rem // Create destination directory, hide potential error messages: 2> nul mkdir "C:\test2\%%~F\.." rem // Actually copy file, hide summary line: > nul copy /Y "C:\test1\%%~F" "C:\test2\%%~F" && ( rem // Return currently copied file: set /A "COUNT+=1" & echo(%%~F ) || ( rem // Return message in case an error occurred: >&2 echo ERROR: could not copy "%%~F"! ) ) ) echo %COUNT% file^(s^) copied. 属性等于touched。我当前的代码执行此操作,但它会引发错误true

Cannot set property touched of #<AbstractControl> which has only a getter

如何将每个输入的addressForm: FormGroup; ... this.addressForm = this._fb.group({ street: ["", [<any>Validators.required]], city: ["", [<any>Validators.required]], state: ["", [<any>Validators.required]], zipCode: ["", [<any>Validators.required]], country: ["", [<any>Validators.required]] }); ... for (var key in this.addressForm.controls) { this.addressForm.controls[key].touched = true; } 值设置为touched

1 个答案:

答案 0 :(得分:0)

如果您在HTML表单元素上使用#myForm="ngForm",则可以访问HTML中的myForm.submitted,因此可能不必担心.touched