提问人:Wacksmart 提问时间:9/30/2023 最后编辑:Wacksmart 更新时间:9/30/2023 访问量:38
Primeng p-selectbutton onOptionClick 事件
Primeng p-selectbutton onOptionClick event
问:
我尝试为 primeng p-selectbutton 创建一个取消选择功能。当我单击已选择的值时,我有一个是/否 p-select按钮,我想清除该变量。
所以我选择“true”,按钮变成“true”,我选择“false”,它变成false,如果我再次点击false,它就会变成null。
HTML格式:
<p-selectButton
[options]="optionsYesNo"
id="myvariable"
name="myvariable"
[(ngModel)]="myvariable"
(onOptionClick)="test('myvariable', $event)"></p-selectButton>
Ts:
test(variable, event){
if (this[variable] === event.option.value) {
this[variable] = null;
} else {
this[variable] = event.option.value;
}
// Update the p-selectButton in the DOM
this.changeDetectorRef.detectChanges();
}
这段代码似乎有效,当选择“true”并再次单击时,DOM 已更新,我的 p-selectbutton 似乎被取消选择,但 myvariable 的值仍为“true”(我用另一个独立的按钮启动对其进行了测试)。console.log(this.myvariable)
答: 暂无答案
评论