我正在处理此表单并希望在输入时进行验证。当前的行为是我选择输入,键入,当我单击其他站点时,它会显示错误。我认为当我设置控制、有效和脏时发生的错误,但我无法弄清楚。
打字稿
buildForm(): void {
this.userForm = this.fb.group({
'email': ['', [
Validators.required,
Validators.pattern('[a-z0-9._%+-]+@[a-z0-9.-]+\.[a-z]{2,3}$')
]
],
'password': ['', [
Validators.required,
Validators.minLength(6),
Validators.maxLength(25)
]
],
});
this.userForm.valueChanges.subscribe(data => this.onValueChanged(data));
}
onValueChanged(data?: any) {
if (!this.userForm) { return; }
const form = this.userForm;
for (const field in this.formErrors) {
// clear previous error message (if any)
this.formErrors[field] = '';
const control = form.get(field);
if (control && control.invalid && control.dirty) {
const messages = this.validationMessages[field];
for (const key in control.errors) {
this.formErrors[field] += messages[key] …
Run Code Online (Sandbox Code Playgroud) angular-material angular angular-reactive-forms angular-forms
我是新的反应,我试图在1秒后改变状态
export class Header extends Component {
constructor() {
super()
this.state = {name: 'Will'}
}
render() {
setTimeout(() => {
this.setState({ name: 'Bob' })
}, 2000);
return (
<h1>
{this.state.name}
</h1>
)
}
}
Run Code Online (Sandbox Code Playgroud)
但是给了我这个警告
警告:只能更新已安装或安装的组件.这通常意味着您在已卸载的组件上调用了setState,replaceState或forceUpdate.这是一个无操作.请检查Header组件的代码.