HTML代码
<li class="dropdownfilter" *ngIf="this.arr.inclues('Male')" (click)="getValueGender('Male',1,)" [(ngModel)]="M"><a>Male</a></li>
我遇到了下面这个异常:
ERROR Error: No value accessor for form control with unspecified name attribute
所以我已经添加了。
<li class="dropdownfilter" name="gendermale" *ngIf="this.arr.inclues('Male')" (click)="getValueGender('Male',1,)" [(ngModel)]="M"><a>Male</a></li>
现在面临以下异常
ERROR Error: No value accessor for form control with name: 'gendermale'
我在我的代码中的许多地方都遇到了这个异常。
<div class="col-sm-8 col-xs-8 contact">
<input id="passphn{{bus.busServiceId}}" (keyup)="onKeyPress($event)" class="form-control contact-number" type="text" [(ngModel)]="contactNumber" name="contact-number" placeholder="Phone" required pattern="(?<!\d)\d{10}(?!\d)" minlength="10" maxlength="10" />
<div class="shake-tooltip-web-mobile" *ngIf="webMobileError != ''">{{webMobileError}}</div> <!-- Facing the same exception here -->
</div>
<div class="panel-body" *ngIf="dropingView == 'show'"> <!-- Here too -->
[(ngModel)]
指令,因为它不是一个表单元素。 - user184994input
标签,它们是li
标签,这就是为什么它无法工作的原因。由于li
没有值,所以您无法绑定到值属性(这就是ngModel
的作用), - user184994ngModel
指令,那么可能会导致该错误。它必须仅用于像input
或select
这样的控件上。 - user184994