【发布时间】:2018-10-30 05:00:20
【问题描述】:
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)]指令,因为它不是表单元素 -
(ngModel) [(ngModel)] [ngModel] 我可以使用哪一个?我可以在哪里使用?请告诉我
-
你想要达到什么目的?
-
但这些不是
input标签,它们是li标签,这就是它不起作用的原因。您不能绑定到 value 属性(这是ngModel所做的),因为lis 没有值 -
如果您对任何不是表单控件的东西都有
ngModel指令,那么这可能会导致该错误。它只能在input或select之类的东西上
标签: angular typescript angular-ngmodel