加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

形式 – 角度2:禁用输入更改不工作

发布时间:2020-12-17 09:41:35 所属栏目:安全 来源:网络整理
导读:直到“最终”2.0的角度我已经做到了: input type="text" formControlName="name" [disabled]="!showName" 动态禁用/启用表单输入. 从Rc7升级到2.0后,我在控制台窗口中得到这个警告: It looks like you’re using the disabled attribute with a reactive f
直到“最终”2.0的角度我已经做到了:
<input type="text" formControlName="name" [disabled]="!showName">

动态禁用/启用表单输入.

从Rc7升级到2.0后,我在控制台窗口中得到这个警告:

It looks like you’re using the disabled attribute with a reactive form directive. If you set disabled to true
when you set up this control in your component class,the disabled attribute will actually be set in the DOM for
you. We recommend using this approach to avoid ‘changed after checked’ errors.

我已经改变了我的代码,按照这些说明:

this._userGroupUsersForm = this._formBuilder.group({
        'users': [{'',disabled: this.showName},Validators.compose([Validators.required,Validators.minLength(3),Validators.maxLength(50),Validators.pattern("^[a-zA-Z?????? 0-9_-]+$")])]
    });

这对于初始页面加载工作正常,但是我不能再像这样切换状态:

toggleName() : void { this.showName = !this.showName; }

我该如何解决?

注意:我的“旧”方式(通过设置[disabled])不起作用.

这应该工作
toggleName() : void { 
  let ctrl = this.form.get('name')
  ctrl.enabled ? ctrl.disable() : ctrl.enable()
}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读