我從角度材質的mat-checkbox出現問題。我已經給該複選框的ID是這樣的:角度mat-checkbox getElementById
<mat-checkbox class="toolbar-checkbox" id="myCheckbox">
MyCheckbox
</mat-checkbox>
之後,我想的東西與此元素是這樣的:
(<MatCheckbox>document.getElementById('myCheckbox')).checked = true;
但unfortunally我得到這個錯誤:
TS2352: Type 'HTMLElement' cannot be converted to type 'MatCheckbox'.
Property '_changeDetectorRef' is missing in type 'HTMLElement'.
(<MatCheckbox>document.getElementById('asdasd')).checked = true;
我該如何解決這個問題,或者是否有更好的方法來使用複選框而不使用[(ngModel)]?
主席先生,讓我高興 - 你打敗了我! – rinukkusu
Danke Schon @rinukkusu \ o / – Faisal