[英]Displaying img in Angular form gives “No value accessor for form control with unspecified name attribute”
I'm displaying a set of icons on top of an image in my ngForm. 我在ngForm中的图像上方显示一组图标。 When dragging the icons around, I save the new location when form is submitted.
拖动图标时,提交表单后,我将保存新位置。 Works fine but I get an annoying error when the page is displayed.
工作正常,但显示页面时出现烦人的错误。
Error 错误
No value accessor for form control with unspecified name attribute 没有用于具有未指定名称属性的表单控件的值访问器
app.component.html app.component.html
<form (ngSubmit)="onSubmit()" #settingsForm="ngForm">
<img #maplocations *ngFor="let loc of locations" class="map-icon"
[src]="loc.getMapImage()"
[style.left.px]="loc.mapleft" [style.top.px]="loc.maptop"
data-html="true"/>
</form>
app.component.ts I include the NgForm in my component app.component.ts我在组件中包含NgForm
import { NgForm } from '@angular/forms';
Why does it complain? 为什么会抱怨?
Okay so I think I found the error... The error was not in the *ngFor as the error details tried to say. 好的,所以我想我找到了错误...该错误不在* ngFor中,因为该错误的详细信息试图说明。 It was with a label further down the page:
它在页面的下方带有一个标签:
<label [ngModelOptions]="{standalone: true}" [(ngModel)]="selectedLocation.name"></label>
Removed the label and now the error is gone. 删除标签,现在错误消失了。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.