我正在嘗試使用Angular 2 Forms進行驗證,但是當我嘗試添加多個控件時。它似乎只是被忽略。我遵循了許多不同的指南來看看其他人是如何做到這一點的,但這些方法似乎都沒有奏效。Angular 2 Form「找不到控件」
我一直在做的是這在我的模板:
<form [formGroup]="form" novalidate (ngSubmit)="save(form.valid)">
<div class="row" id="message-wrapper">
<label>Message</label>
<small [hidden]="form.controls.message.valid || (form.controls.message.pristine && !submitted)">
Message is required (minimum 10 characters).
</small>
<textarea
class="textarea-scaled"
type="text"
[(ngModel)]="campaign.message"
formControlName="message"
placeholder="This will be sent out by supporters with a URL back to this campaign">
</textarea>
</div>
<div class="row" id="promo-wrapper">
<label>Promotion: </label>
<small [hidden]="form.controls.promotion.valid ||(form.controls.promotion.pristine && !submitted)">
Promotion is required and should be between 10 and 100 characters
</small>
<textarea
class="textarea-scaled"
type="text"
[(ngModel)]="campaign.promotion"
formControlName="promotion"
placeholder="What would you like to be sent out in promotional messages?">
</textarea>
</div>
</form>
然後在我的部分我這樣做:
form: FormGroup;
constructor(private builder: FormBuilder,
private _dataservice: DataService) {
this.form = builder.group({
"message": ['', [Validators.required, Validators.minLength(10)]],
"promotion": ['', [Validators.required, Validators.minLength(10)]]
});
}
但我不斷收到「無法找到控制‘促銷’」控制檯錯誤...
任何幫助將不勝感激!
您是否已將REACTIVE_FORM_DIRECTIVES元素添加到組件? – micronyks
是的,這是在我的指令。對不起,我沒有表現出來。 –
你可以請求重生嗎? – micronyks