将选项设置为 select previous 后启用 select 控制
enable select control after setting option to select previous
我有一个带有 select 控件的表单,当 select 一个时,应该禁用相应的控件:
尝试将一个flag初始化为false,在执行onChange方法时将其改为true,但还是不行。我留下一些代码:
<div class="form-group">
<div class="form-row">
<div class="col-md-6">
<label>AREA DE SERVICIO*</label>
<select (change)="cargaSelectTipoReclamo()" formControlName="areaServicio" class="form-control" placeholder="Seleccione Area de Servicio">
<option value="" disabled>Seleccione Área de Servicio...</option>
<option *ngFor="let item of arrArServ" [value]="item.arServ_IDAreaServicio">
{{ item.arServ_nombre }}
</option>
</select>
</div>
<div class="col-md-6">
<label>RECLAMO*</label>
<select [disabled]="boTipRec === true" id="ddlReclamo" (change)="selectTipoReclamo()" formControlName="tipoReclamo" [(ngModel)]="TipoReclamoID" class="form-control">
<option value="" disabled>Seleccione Reclamo</option>
<option *ngFor="let item of arrTipRec" [value]="item.tipRec_IDTipoReclamo">
{{ item.tipRec_nombre }}
</option>
</select>
</div>
</div>
</div>
TS:
boTipRec = false;
cargaSelectTipoReclamo() {
try {
this.objIDArServ = {
tipRec_IDArServ: this.frmGenerar.areaServicio.value
};
this.ddlService.selectTipoReclamo(this.objIDArServ).subscribe(data => {
this.arrTipRec = JSON.parse(data);
this.arServ = this.arrArServ.filter(x => x.arServ_IDAreaServicio === +this.frmGenerar.areaServicio.value)[0];
this.selectTipoReclamo();
});
if (this.objReclamo === null) {
this.frmGenerar.tipoReclamo.setValue('');
this.boTipRec = true;
}
} catch (error) {
console.log(error);
}
}
有什么想法吗?
这应该有效,只要它实际进入您的 if 子句即可。
你确定 this.objReclamo
真的是 null
吗?
这是一个简单的示例,其中包含一个更改事件,展示了它是如何工作的:
https://stackblitz.com/edit/angular-pucc3q
我有一个带有 select 控件的表单,当 select 一个时,应该禁用相应的控件:
尝试将一个flag初始化为false,在执行onChange方法时将其改为true,但还是不行。我留下一些代码:
<div class="form-group">
<div class="form-row">
<div class="col-md-6">
<label>AREA DE SERVICIO*</label>
<select (change)="cargaSelectTipoReclamo()" formControlName="areaServicio" class="form-control" placeholder="Seleccione Area de Servicio">
<option value="" disabled>Seleccione Área de Servicio...</option>
<option *ngFor="let item of arrArServ" [value]="item.arServ_IDAreaServicio">
{{ item.arServ_nombre }}
</option>
</select>
</div>
<div class="col-md-6">
<label>RECLAMO*</label>
<select [disabled]="boTipRec === true" id="ddlReclamo" (change)="selectTipoReclamo()" formControlName="tipoReclamo" [(ngModel)]="TipoReclamoID" class="form-control">
<option value="" disabled>Seleccione Reclamo</option>
<option *ngFor="let item of arrTipRec" [value]="item.tipRec_IDTipoReclamo">
{{ item.tipRec_nombre }}
</option>
</select>
</div>
</div>
</div>
TS:
boTipRec = false;
cargaSelectTipoReclamo() {
try {
this.objIDArServ = {
tipRec_IDArServ: this.frmGenerar.areaServicio.value
};
this.ddlService.selectTipoReclamo(this.objIDArServ).subscribe(data => {
this.arrTipRec = JSON.parse(data);
this.arServ = this.arrArServ.filter(x => x.arServ_IDAreaServicio === +this.frmGenerar.areaServicio.value)[0];
this.selectTipoReclamo();
});
if (this.objReclamo === null) {
this.frmGenerar.tipoReclamo.setValue('');
this.boTipRec = true;
}
} catch (error) {
console.log(error);
}
}
有什么想法吗?
这应该有效,只要它实际进入您的 if 子句即可。
你确定 this.objReclamo
真的是 null
吗?
这是一个简单的示例,其中包含一个更改事件,展示了它是如何工作的:
https://stackblitz.com/edit/angular-pucc3q