[英]No value accessor for form control with unspecified name attribute in angular 5
HTML code HTML代码
<li class="dropdownfilter" *ngIf="this.arr.inclues('Male')" (click)="getValueGender('Male',1,)" [(ngModel)]="M"><a>Male</a></li>
I'm facing the below exception 我面临以下异常
ERROR Error: No value accessor for form control with unspecified name attribute
So I have added 所以我加了
<li class="dropdownfilter" name="gendermale" *ngIf="this.arr.inclues('Male')" (click)="getValueGender('Male',1,)" [(ngModel)]="M"><a>Male</a></li>
Now facing the below exception 现在面临以下异常
ERROR Error: No value accessor for form control with name: 'gendermale'
I'm facing this exception in many places of my code. 我在代码的许多地方都遇到了这个异常。
<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 -->
First of all, you can't access with this.x in html. 首先,您无法使用html中的this.x进行访问。
<li class="dropdownfilter" *ngIf="arr.inclues('Male')" (click)="getValueGender('Male',1)"><a>Male</a></li>
Secondly, li tag doesnt have name attribute nor supports [(ngModel)] because it requires value property. 其次,li标签没有名称属性,也不支持[[ngModel)],因为它需要value属性。 ngModel is an angular build in directive.
ngModel是一个有角度的内置指令。 Two-way binding uses the syntax as [()], Property binding uses the syntax [] and Event binding uses the syntax as parenthesis ().
双向绑定将语法用作[()],属性绑定使用语法[],事件绑定使用语法作为括号()。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.