【发布时间】:2018-05-24 22:32:40
【问题描述】:
我正在开发 Angular 5 应用程序。我有反应形式,它们都工作正常。现在,当用户单击复选框 true 时,我需要禁用输入。一切正常,我想知道如何禁用组件的输入。我成功获得了输入的 id 但不确定下一步该怎么做???
组件
private handleQuestionAnswerProvidedStateChange(questionAnswerProvidedState:QuestionAnswerProvidedStateDataModel)
{
console.log(">>>>>>> questionAnswerProvidedStateEvent ",questionAnswerProvidedState);
var elementReference = document.getElementById(questionAnswerProvidedState.QuestionId);
console.log("elementReference ",elementReference);
}
模板
<div *ngSwitchCase="'textbox'"> <small>textbox</small>
<div class="form-group">
<input *ngSwitchCase="'textbox'"
[formControlName]="question.key"
[id]="question.key"
[type]="question.type"
[(ngModel)]="question.value"
(keyup.enter)="onChangeValue($event, previousValue, responseId, question.key, 'textbox'); previousValue = question.value"
(blur)="onChangeValue($event, previousValue, responseId, question.key, 'textbox'); previousValue = question.value"
(focus)="previousValue=question.value"
>
</div>
</div>
后面的文字是循环的,所以会有很多输入,每个都有唯一的id
【问题讨论】:
-
在组件文件中使用
ViewChild()作为输入元素并设置disabled = true -
在您的打字稿代码中,测试您的复选框,如果选中则禁用输入字段
-
做这样的事情:
if (document.getElementById("CheckBoxId").checked == true){ document.getElementById("textFieldId").disabled = true; } -
寻找 Pipe+ReactiveForm+Disable
标签: angular angular-reactive-forms