私はこのように、別のコンポーネントからの入力で、データ駆動型フォームを構築しようとしている:角度2 - フォームグループコンポーネント
: は<form [formGroup]="signupForm" (ngSubmit)="onSubmit()">
<app-form-group [name]="name"></app-form-group>
<app-form-group [name]="email"></app-form-group>
<app-form-group [name]="other"></app-form-group>
</form>
app-form-group
コンポーネントは次のようになります
<div class="form-group">
<label class="col-md-2 control-label">{{Name}}</label>
<div class="col-md-9">
<input class="form-control" [name]="name" [formControlName]="formCtrlName">
</div>
問題は、したがって、私はこのエラーを取得し、formControlName
はformGroup
ディレクティブを必要としていることである。
Error : Error in ./FormGroupComponent class FormGroupComponent - inline template:3:58 caused by: formControlName must be used with a parent formGroup directive.You'll want to add a formGroup
directive and pass it an existing FormGroup instance (you can create one in your class).
この問題を回避する方法はありますか?
http://blog.thoughtram.io/angular/2016/07/27/custom-form-controls- in-angular-2.html –