我正在动态渲染复选框和组合框字段并执行以下功能:
组合框字段适用于第一种情况但不适用于第二种情况。状态(启用或禁用)以后不能更改。
这是我的模板代码段:
< tr *ngFor="let widgetAttribute of _preferencesWidget">
< td *ngFor="let subattribute of widgetAttribute.methods">
< select *ngIf="subattribute.name == 'Email' && subattribute.type == 'LIST'" id="{{subattribute.name}}Check" class="selectpicker" data-max-options="1" (change)="validateCombo($event)"
[disabled]="!subattribute.enabled">
<option *ngFor="let subValue of subattribute.values" value="{{subValue.code}}" [selected]="subValue.code == subattribute.selected">{{subValue.description}}< /option>
< /select>
< /td>
< /tr>
复选框的生成ID为: InformationCheck ,对于组合框: pensionMCheck
我的组件逻辑是:
public validateCombo() {
if (this.pensionCheck) {
$('#pensionMCheck').prop('disabled', false);
if ($('#pensionMCheck').val() === 'Y') {
this.pensionMCheck = true;
} else {
this.pensionMCheck = false;
}
} else {
this.pensionMCheck = false;
$('#pensionMCheck').val('N');
$('#pensionMCheck').prop('disabled', true);
$('#pensionMCheck').prop('selectedIndex', 0);
}
答案 0 :(得分:1)
将复选框状态绑定到属性(isChecked
)并将enabled
的{{1}}绑定到同一属性:
<select>