数组拼接后* ng不更新表单输入名称。
<div class="row p-t-20" *ngFor="let multiple_option of questions.options; let i=index">
<div class="col-md-10">
<div class="form-group">
<label class="control-label">Option {{i + 1}}</label>
<input type="text" [(ngModel)]="multiple_option.value" class="form-control" name="radioBtn_{{i}}" #radioBtn="ngModel" required >
</div>
</div>
<div class="col-md-1">
<button type="button" class="btn btn-success btn-circle" (click)="addOption()"><i class="fa fa-plus"></i> </button>
</div>
<div class="col-md-1" [hidden]="i == 0">
<button type="button" class="btn btn-warning btn-circle" (click)="removeOption(i)"><i class="fa fa-minus"></i> </button>
</div>
{{f.value | json}}
{ “question0”:“scascsac”, “selectElem0”:“radio_button”, “is_other0”:false, “radioBtn_0”:“ascsacsac”, “radioBtn_2”:“asccscascssaccsacsscsca”, “radioBtn_3”:“ascsacsacsacsacsac” }
addOption(){
this.f._submitted = false;
this.questions.options.push({logic : {}});
}
removeOption(指数){
this.questions.options.splice(index,1);
console.log(this.questions.options);
}
我在以下链接中复制了以上场景:
https://stackblitz.com/edit/angular-kzyfky?file=app%2Fapp.component.html
答案 0 :(得分:1)
删除名称并添加[ngModelOptions] =&#34; {standalone:true}&#34;