为什么这很好用单击幻灯片切换时,I.E isPrint显示为真或假
<div>
<mat-slide-toggle [(ngModel)]="isPrint" #toggleSlide></mat-slide-
toggle>
isPrint: {{ isPrint }}
</div>
但这不起作用并给出错误ERROR错误:没有值的访问器用于具有未指定的name属性的表单控件
<div>
<mat-button-toggle [(ngModel)]="isPrint" #toggleBtn>Toggle</mat-button-toggle>
isPrint: {{ isPrint }}
</div>
我做得不好?
因此,MatButtonToggle component doesn't implement ControlValueAccessor,你不能使用[(ngModel)]
。
MatButtonToggle应该是mat-button-toggle-group的一部分。
但是如果你想将它作为一个独立的组件使用并将模型绑定到它,你必须做如下的事情:〜
<mat-button-toggle
[checked]="isPrint"
(change)="isPrint = $event.source.checked">
Toggle
</mat-button-toggle>