【发布时间】:2018-03-31 15:31:10
【问题描述】:
我在使用 angular material 的 mat-checkbox 时遇到了问题。我已经为复选框提供了这样的 ID:
<mat-checkbox class="toolbar-checkbox" id="myCheckbox">
MyCheckbox
</mat-checkbox>
在那之后,我试图用这个元素做一些这样的事情:
(<MatCheckbox>document.getElementById('myCheckbox')).checked = true;
但不幸的是,我收到了这个错误:
TS2352: Type 'HTMLElement' cannot be converted to type 'MatCheckbox'.
Property '_changeDetectorRef' is missing in type 'HTMLElement'.
(<MatCheckbox>document.getElementById('asdasd')).checked = true;
我该如何解决这个问题,或者有没有更好的方法来使用复选框而不使用 [(ngModel)]?
【问题讨论】:
标签: angular angular-material angular-material2