表单form中input组件设置disable未生效 - Angular

当 input 与表单 form 的相结合使用的时候,如果为 input 设置 [disabled]="false" 的属性时发现未能生效;
日志中会抛出如下警告并提供一种方式;

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.

      Example:
      form = new FormGroup({
        first: new FormControl({value: 'Nancy', disabled: true}, Validators.required),
        last: new FormControl('Drew', Validators.required)
      });

另外可以通过不同的事件中单独控制,具体如下:

// 可编辑
this.scoreTableForm.controls.scoreName.enable();
// 不可编辑
this.scoreTableForm.controls.scoreName.disable();

以上两种方式均可实现其相同的效果,根据实际应用场景自行选择即可.


以上便是此次分享的全部内容,希望能对大家有所帮助!

  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值