首页 > 解决方案 > Renderer2 启用/禁用 Mat-radio-button-group

问题描述

我有一个 mat-radio-button-group 以禁用开始,并希望以编程方式更改禁用值

@ViewChild('voice_card_choices') voiceCardChoices: ElementRef; 

this.renderer.setProperty(this.voiceCardChoices, 'disabled', false); // Doesn't work
this.voiceCardChoices.disabled = false; // Doesn't work, just creates a new property called disabled on the object
this.voiceCardChoices.nativeElement.disabled = false; //Doesn't work, same case as above

尝试同时使用Renderer2theElementRef和 the nativeElement,似乎没有任何效果

标签: angular

解决方案


如果你改变ElementRefMatRadioButtonMatRadioButtonGroup工作

此代码无需渲染即可工作

constructor(public renderer: Renderer2) {} 
@ViewChild('voice_card_choices') voiceCardChoices: MatRadioButton || ElementRef ; 

functionToDisableDropDown() {
  this.voiceCardChoices.disabled = true;
}

希望有用


推荐阅读