【发布时间】:2020-09-20 18:17:08
【问题描述】:
我有一个属性指令可以修改宿主元素的选中状态。我正在使用以下代码来执行此操作:
constructor(private el: ElementRef, private model: NgModel) {}
//OnInit code
if ('ng-reflect-model' in this.el.nativeElement.attributes) { <-- Problem is here, this attribute is available for debug, i want to put some condition here
this.model.viewToModelUpdate(modelValue);
this.model.valueAccessor.writeValue(modelValue);
} else {
this.el.nativeElement.checked = modelValue;
}
我的问题是当输入有 ngModel 与之关联时,如果模型可用,我想更新模型,否则更新本机元素的已检查状态。
【问题讨论】: