我选择单选按钮时,Angular-Material单选按钮数据未绑定

时间:2018-07-31 06:57:38

标签: angular angular-material2

此处将我的代码从引导程序升级到Angular Material 这是我的Bootstrap代码,可以正常工作

 <input  type="radio" class="form-control input-sm" value="Act" (change)="onSelectionChange('Act')"  name="sectionType" #sectionType="ngModel"  id="rdb1" checked=true  ngModel required>Act

我改成

<mat-radio-group >
    <mat-radio-button  [value]="Section" (change)="onSelectionChange('Section')"name="sectionType" #sectionType="ngModel"  ngModel>Section</mat-radio-button>
</mat-radio-group>

为什么我无法绑定数据?

1 个答案:

答案 0 :(得分:1)

mat-radio-group级别而不是mat-radio-button级别使用数据绑定:

<mat-radio-group [(ngModel)]="sectionType">
    <mat-radio-button  value="Section" (change)="onSelectionChange('Section')" name="sectionType">Section</mat-radio-button>
</mat-radio-group>

您可以参考this官方指南。

相关问题