angular - 如何在角度禁用的情况下传递选择的值?
问题描述
您好,我正在使用选择禁用将值传递给输入,但是在没有禁用之前我找不到方法我使用了这个:
private subscribeToForm = () => {
this.form.get('idLinea').valueChanges.subscribe(value => {
console.log(value)
this.handleIdLineaChange(value);
}); }
在这里我使用该值在输入中显示它
private handleIdLineaChange = (value) => {
if (value) {
const idTipoLinea = this.form.get('idLinea').value;
console.log(idTipoLinea)
const fechaEvento = this.form.get('fechaEvento').value;
let fecha = new Date(fechaEvento);
this.presupuestoService.getPresupuesto(idTipoLinea, fecha.getFullYear()).subscribe((resp) => {
const pto = resp.data[0];
this.form.patchValue({
presupuestoAsignadoLinea: pto.ptoAsignado,
presupuestoUsado: pto.ptoUsado,
presupuestoDisponible: pto.ptoDisponible
});
}, () => {
this.toastService.warning(MESSAGES.NO_EXISTE_PRESUPUESTO);
});
} else {
this.form.patchValue({
presupuestoAsignadoLinea: null,
presupuestoUsado: null,
presupuestoDisponible: null
});
}
}
html
<div class="col-md-2">
<lib-form-control isRequired
label="Línea"
variant="select"
placeholder
controlName="idLinea"
bindValue="idParam"
bindLabel="valor"
[formGroupParent]="form"
[options]="state.comboLists.linea.list"
[disabled]="true"
>
</lib-form-control> </div>
解决方案
this.form.get('idLinea').value 无论如何都应该工作
我认为您的问题是 valueChanges 未执行。我认为您首先需要startWith
在 valueChanges 中使用 rxjs/operator 来执行更改
this.form
.get('idLinea')
.valueChanges.pipe(
startWith(this.form.get('idLinea').value))
.subscribe(value=> {
this.handleIdLineaChange(value);
});
看看这个傻瓜stackblitz
推荐阅读
- c++ - 我为 Evil Hangman 的构造函数遗漏了什么吗?
- react-native - 如何设置标题的背景视图
- google-apps-script - 如何在将在数组内工作的方法中设置参数?(谷歌应用脚本)
- java - 使用 Spring RetryTemplate 时获取当前退避值
- python - 如何将打印的 for 循环值写入 csv 文件?
- python - Python - 当数据不是数字时如何从 csv 文件制作条形图
- javascript - 根据另一个表的索引获取数组的元素
- msbuild - 如何在 .wixproj 文件中设置“env”预处理器变量
- awk - awk '/matched/,0' 文件中的 0 是什么意思?
- c - 二维结构数组:交换行和列?