具有未指定名称属性的表单控件没有值访问器 [英] No value accessor for form control with unspecified name attribute

查看:30
本文介绍了具有未指定名称属性的表单控件没有值访问器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嘿,我将我的滑块数据绑定到值为 1 和 0 的属性.在 1 上,开关应该处于活动状态,在 0 上则不应该.我成功地对一些输入和选择元素进行了数据绑定,但在滑块上我遇到了以下错误:

<块引用>

未指定名称属性的表单控件没有值访问器

这是我的 HTML 部分:

离开<mat-slide-toggle [(ngModel)]="endless" #ctrl="ngModel" name="endless"id="endless"></mat-slide-toggle>在

我周围没有任何表单,而且我还有一个 name 属性,所以我不明白为什么会发生这个错误!感谢您的帮助!

编辑

这是整个 Mat-Card 块:

 <div class="flexcontainercolumn"><div class="flexcontainerrow"><div><mat-icon class="suffixicon" aria-label="person">今天</mat-icon>

<div class="flexcontainerrow100"><label>Endlos</label><div class="slidercontrainer">离开<mat-slide-toggle [checked]="endless" [(ngModel)]="endless" name="endless" id="endless"></mat-slide-toggle>在

<mat-form-field class="startdatecont" [(ngModel)]="startdate"><input matInput [matDatepicker]="picker1" placeholder="Startdatum" [value]="startdate"><mat-datepicker-toggle matSuffix [for]="picker1"></mat-datepicker-toggle><mat-datepicker #picker1></mat-datepicker></mat-form-field><mat-form-field *ngIf="en​​dless == 0" class="enddatecont"><input matInput [matDatepicker]="picker2" placeholder="Enddatum"><mat-datepicker-toggle matSuffix [for]="picker2"></mat-datepicker-toggle><mat-datepicker #picker2></mat-datepicker></mat-form-field>

</mat-card>

编辑 2

添加了Stackblitz(控制台中显示错误)

解决方案

我通过简单的删除和插入元素来解决它.这个好像有点坑.表单字段控制错误也有同样的问题.删除并插入它解决了问题.

Hey iam Databinding my slider to an attribute whit the values 1 and 0. On 1 the switch should be active, on 0 it shouldnt. I successfully Databinded some Input and Select Elements but at the Slider i run into following error:

No value accessor for form control with unspecified name attribute

This is my HTML part:

<div class="slidercontainer aftericn">
   Off
   <mat-slide-toggle [(ngModel)]="endless" #ctrl="ngModel" name="endless" 
   id="endless"></mat-slide-toggle>
   On
</div>

I do not have any Form arround it, and i also have a name attribute, so i dont understand why this error happens! Thanks for any help!

EDIT

Here is the whole Mat-Card Block:

  <mat-card class="inputdatacard">
     <div class="flexcontainercolumn">
        <div class="flexcontainerrow">
           <div>
              <mat-icon class="suffixicon" aria-label="person">today
              </mat-icon>
           </div>
           <div class="flexcontainerrow100">
              <label>Endlos</label>
              <div class="slidercontrainer">
                 Off
                 <mat-slide-toggle [checked]="endless" [(ngModel)]="endless" name="endless" id="endless"></mat-slide-toggle>
                 On
              </div>
           </div>
        </div>
        <mat-form-field class="startdatecont" [(ngModel)]="startdate">
           <input matInput [matDatepicker]="picker1" placeholder="Startdatum" [value]="startdate">
           <mat-datepicker-toggle matSuffix [for]="picker1"></mat-datepicker-toggle>
           <mat-datepicker #picker1></mat-datepicker>
        </mat-form-field>

         <mat-form-field *ngIf="endless == 0" class="enddatecont">
           <input matInput [matDatepicker]="picker2" placeholder="Enddatum">
           <mat-datepicker-toggle matSuffix [for]="picker2"></mat-datepicker-toggle>
           <mat-datepicker #picker2></mat-datepicker>
        </mat-form-field>
     </div>
  </mat-card>

EDIT 2

Added Stackblitz (Error shows up in Console)

解决方案

I have solved it by simple deleting and inserting the element. Seems like this is a bit bugged. Got the same problem whit form-field-control error. Deleteing and Inserting it solved the Issue.

这篇关于具有未指定名称属性的表单控件没有值访问器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
前端开发最新文章
热门教程
热门工具
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆