gpt4 book ai didi

angular2 不会根据 true 或 false 条件禁用输入

转载 作者:太空狗 更新时间:2023-10-29 17:16:40 26 4
gpt4 key购买 nike

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

如果更改 radio ,我会看到该值更改为 true 或 false:

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

那么wow为什么会根据true换false来禁用输入框呢?

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

编辑:

在日志中我得到这个:

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 中使用了一个响应式(Reactive)。

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

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

})

那么我是否可以根据 radio 输入的切换来启用?

最佳答案

尝试使用 attr.disabled,而不是禁用

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

StackOverflow Answer

关于angular2 不会根据 true 或 false 条件禁用输入,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39325293/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com