如何使用渲染器重置容器的子属性?
how can i reset the child attributes of a container using renderer?
在一个容器中,我有下拉菜单和多个 select 以及数量 select。
单击按钮我想重置组件的状态。
<input #select type="checkbox" value="somevalue"/>
在组件中我有一个 viewChildren
@ViewChildren('select') selectReference:QueryList<ElementRef>;
在按钮的点击事件上,我正在尝试这样的事情:
submitProduct(){
for(let currentelRef of this.selectReference.toArray()){
console.log(currentelRef);
this.render.setProperty(this.selectReference,'checked',false);
}
}
但这不起作用。
我怎样才能做到这一点?
任何指点将不胜感激。
我建议使用 ngModel
或 FormGroup
,然后在您的组件中将模型设置为 false。无需以这种方式查询复选框。
但是,如果您想使用渲染器,则需要将每个 ElementRef
:
的 nativeElement
作为目标
this.render.setProperty(currentelRef.nativeElement, "checked", false);
在一个容器中,我有下拉菜单和多个 select 以及数量 select。 单击按钮我想重置组件的状态。
<input #select type="checkbox" value="somevalue"/>
在组件中我有一个 viewChildren
@ViewChildren('select') selectReference:QueryList<ElementRef>;
在按钮的点击事件上,我正在尝试这样的事情:
submitProduct(){
for(let currentelRef of this.selectReference.toArray()){
console.log(currentelRef);
this.render.setProperty(this.selectReference,'checked',false);
}
}
但这不起作用。 我怎样才能做到这一点?
任何指点将不胜感激。
我建议使用 ngModel
或 FormGroup
,然后在您的组件中将模型设置为 false。无需以这种方式查询复选框。
但是,如果您想使用渲染器,则需要将每个 ElementRef
:
nativeElement
作为目标
this.render.setProperty(currentelRef.nativeElement, "checked", false);