Binding Mat-Button-Toggle v binding Mat-Slide-Toggle
这怎么正常工作。 I.E isPrint在单击幻灯片切换器
时显示为true或false
1 2 3 | <mat-slide-toggle [(ngModel)]="isPrint" #toggleSlide></mat-slide- toggle> isPrint: {{ isPrint }} |
但这不起作用,并显示错误ERROR错误:具有未指定名称属性的表单控件没有值访问器
1 2 | <mat-button-toggle [(ngModel)]="isPrint" #toggleBtn>Toggle</mat-button-toggle> isPrint: {{ isPrint }} |
我在做什么不正确?
检查工作堆栈
MatButtonToggle组件未实现ControlValueAccessor,
因此,不能在其上使用
MatButtonToggle应该是mat-button-toggle-group的一部分。
但是,如果要将其用作独立组件并绑定模型,则必须执行以下操作:?
1 2 3 4 5 | <mat-button-toggle [checked]="isPrint" (change)="isPrint = $event.source.checked"> Toggle </mat-button-toggle> |