javascript - <垫单选按钮> : No value accessor

标签 javascript html angular angular-material2

我有这个 HTML:

 <mat-radio-group>
  <mat-radio-button  [(ngModel)]="searchType">
      And (Narrower search)
  </mat-radio-button>
  <mat-radio-button  [(ngModel)]="searchType">
       Or (Wider search)
  </mat-radio-button>
 </mat-radio-group>

我收到此错误:

Error: No value accessor for form control with unspecified name attribute

我尝试使用这个:

 <mat-radio-button name="search-and"[(ngModel)]="searchType">
      And (Narrower search)
 </mat-radio-button>

我收到此错误:

Error: No value accessor for form control with name: 'search-and'

然后我尝试了这个:

 <mat-radio-button value="search-and" name="search-and" [(ngModel)]="searchType">
              And (Narrower search)
 </mat-radio-button>

还有这个:

  <mat-radio-button [value]="search-and" name="search-and" [(ngModel)]="searchType">
              And (Narrower search)
  </mat-radio-button>

我仍然收到此错误:

Error: No value accessor for form control with name: 'search-and'

最佳答案

尝试设置formControlName="SearchType"<mat-radio-group>而不是<mat-radio-button> .

关于javascript - <垫单选按钮> : No value accessor,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48515312/

相关文章:

javascript - Google 标签管理器虚拟页面 View

html - 更改 span 元素的高度

php - 比较时间时获取数据

angular - 从 QueryList 中识别特定的 Angular TemplateRef

html - 根据条件禁用输入

javascript - 使用 javascript 在每个文件中使用 <TITLE></TITLE> 重命名多个 HTML 文件

javascript - 复选框 onCheck 不会触发

javascript - 使用 AngularJS 进行 SPA 设计 - 在一些但不是所有页面之间共享状态

c# - 使用 Html helper HiddenFor C# MVC 将模型添加到模型中

angular - 如何让 Angular 动画等待渲染完成