表单控件错误:ERROR错误:具有未指定名称属性的表单控件无值访问器 [英] form control error:ERROR Error: No value accessor for form control with unspecified name attribute
问题描述
在下面的组件中,当将组件加载到angular4应用程序中时,我不断收到错误消息:
In the below component when the component is loaded in the angular4 app I keep getting the error:
ng:///HeaderModule/HeaderComponent.ngfactory.js:334错误错误:否 具有未指定名称属性的表单控件的值访问器
ng:///HeaderModule/HeaderComponent.ngfactory.js:334 ERROR Error: No value accessor for form control with unspecified name attribute
我尝试删除ngModel
和value
属性,但没有任何效果.
I have tried removing ngModel
and value
attributes but nothing has worked.
我假设问题出在标题.component.html上. 下面是html
I'm assuming the issue is with the header .component.html. Below is the html
<!-- Notification area-->
<li class="dropdown">
<a href="#" data-toggle="dropdown" class="dropdown-toggle" (click)="changeNotificationStatus()">
<i class="glyphicon glyphicon-bell"></i>
<span class="visible-xs-inline">Notifications</span>
<span class="badge badge-sm up bg-danger pull-right-xs" [hidden]="notificationCount<=0" [(ngModel)]="notificationCount"></span>
</a>
<div class="dropdown-menu w-xl animated fadeInUp">
不确定是什么原因导致了问题. 如果有人可以指出问题,将会很有帮助.
Not sure what causes the problem. If somebody could point out the issue it will be helpful.
谢谢
推荐答案
如果您忘记为ngModel
指定name
属性,则会发出此错误.
This error is emitted, if you forget to specify the name
attribute for an ngModel
.
您可以在html中找到以下包含错误的行:
You can find following line in your html that contains the error:
<span class="badge badge-sm up bg-danger pull-right-xs" [hidden]="notificationCount<=0" [(ngModel)]="notificationCount"></span>
如您所见,没有name
属性.
这篇关于表单控件错误:ERROR错误:具有未指定名称属性的表单控件无值访问器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!