angular2不会基于正确或错误条件禁用输入 [英] angular2 will not disable input based on true or false condition

查看:175
本文介绍了angular2不会基于正确或错误条件禁用输入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个基于以下内容的输入框:

I have a input box based on the below:

如果更改收音机,我会看到该值更改为true代表false:

If a change a radio I see that the value changes to true for false:

<pre> {{model_parameters_general.estimationmethod=='ew'}} </pre>

那么哇,为什么要基于true还是false禁用输入框?

So wow why will the input box be disabled based on true for false?

<input [disabled]="model_parameters_general.estimationmethod=='ew'" [(ngModel)]="model_parameters_general.lambda" 
                           formControlName="lambda" type="text" class="form-control">

在日志中,我得到这个:

In the logs I get this:

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)
  });

所以我在rc6中使用了反应式.

So I am using a reactive from in rc6.

我将初始禁用设置为以下内容:

I set the initial disable to the below:

this.myForm = fb.group({
                lambda: new FormControl({value: .99, disabled: true}, Validators.required),

        }) 

那么我是否要基于单选输入的启用?

So do I enable based on a toggle of a radio input?

推荐答案

尝试使用attr.disabled而不是Disabled

Try using attr.disabled, instead of disabled

<input [attr.disabled]="disabled?'':null"/>

StackOverflow答案

这篇关于angular2不会基于正确或错误条件禁用输入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆