0
我有一個FormGroup模板驅動驗證。我需要我的公式有一段動態生成的輸入,由ngFor創建。不幸的是,angular2現在需要使用ngModel命名的FormGroup中的每個輸入。我該如何處理它?模板驅動的解決方案是優先考慮的。表單代碼如下:提前驗證動態角度2表格
<form #f="ngForm" (ngSubmit)="createProfile()">
<div class="row align-items-center mb-2">
<div class="col-sm-2">
<b>Name:</b>
</div>
<div class="col-sm-10">
<input type="text" [(ngModel)]="profile.name" class="form-control"
name="profileName" required pattern="[a-zA-Z_][a-zA-Z_\-0-9]*">
</div>
</div>
<div class="channelBox">
<div *ngFor="let c of profile.channels">
<div class="row align-items-center mb-2">
<div class="col-sm-2">
<b>Name:</b>
</div>
<div class="col-sm-10">
<input type="text" [(ngModel)]="c.name" class="form-control" required
pattern="[a-zA-Z_][a-zA-Z_\-0-9]*" name="channelName">
</div>
</div>
<div class="row align-items-center mb-2">
<div class="col-sm-2">
<b>Filter:</b>
</div>
<div class="col-sm-10">
<textarea class="form-control" rows="4" [(ngModel)]="c.filter"
name="channelFilter">
</textarea>
</div>
</div>
<div class="row align-items-center mb-2">
<div class="col-sm-2">
<b>Sources:</b>
</div>
<div class="col-sm-10">
<label *ngFor="let s of c.sources">
<input type="checkbox" [(ngModel)]="s.checked"
name="channelCheck">
{{ s.name }}
</label>
</div>
</div>
</div>
</div>
<div>
<button class="btn btn-success" type="submit" [disabled]="!f.valid">
Create profile
</button>
<button class="btn btn-default" (click)="d('reason')">Cancel</button>
</div>
</form>
感謝您的幫助
不工作。雙引號之間的所有內容都被視爲明文。 – doomista
現在,它的工作,非常感謝! – doomista