【发布时间】:2017-03-01 11:23:52
【问题描述】:
HTML:
<span *ngFor="let cust of customs">
<div class="custominfobackground col-sm-12">
<input type="email" id="widget-subscribe-form-email" name="cust{{$index}}" class="form-control required email" [formControl]="form.controls['custominfo']"
[(ngModel)] = "cust.value" [ngClass]="{ active: submitted && !form.controls['custominfo'].valid}" placeholder="Facebook" aria-required="true">
</div>
</span>
打字稿:
export class Custom {
customs:any = [];
constructor(fbld: FormBuilder, http: Http) {
this.form = fbld.group({
custominfo: ['',Validators.required],
});
}
showCustomInfo(){
this.customs.push("");
}
}
当我点击添加按钮时,会添加一个新输入,但我为第一个输入输入的相同值也适用于第二个输入。谁能帮助我。谢谢。
【问题讨论】:
-
请提供完整的代码。
-
你有混合表单控件和 ngmodel 的原因吗?
-
嗨,AJT_82,我将其包含在验证中。
-
@Daniel 好的,但是为什么不使用表单控件进行验证,因为您已经在使用它们了 :)
-
@Daniel,请提供您的表单组定义