폼 빌더를 통해 빌드 된 폼을 가진 컴포넌트가 있습니다. 이제 폼 컨트롤로 입력 상자가 하나만있는 컴포넌트를 포함해야합니다.FormControl Angular2로 컴포넌트 포함
add.ts
this.newForm = this.fb.group({
name: ['', [Validators.required]],
surname:['', [Validators.required]],
time: ''
});
가 다른 구성 요소로 포함하는 "시간"있다.
add.html
<div class="form-group">
<label class="col-md-3 control-label" for="name">{{'forms.newForm.label.configuration.name' | translate}}</label>
<div class="col-md-3">
<input type="text" formControlName="name" placeholder="placeholder"
class="form-control input-md" type="text">
<small *ngIf="!newForm.controls.name.valid && newForm.controls.name.dirty" class="text-danger">
Name is required.
</small>
</div>
<label class="col-md-3 control-label" for="surname">{{'forms.newForm.label.configuration.name' | translate}}</label>
<div class="col-md-3">
<input type="text" formControlName="surname" placeholder="placeholder"
class="form-control input-md" type="text">
<small *ngIf="!newForm.controls.surname.valid && newForm.controls.name.dirty" class="text-danger">
Surname is required.
</small>
</div>
</div>
time.html
<div>
<div class="col-md-7">
<input class="form-control input-md" type="text" (keydown)="eventHandler($event)" maxlength="11">
<small *ngIf="!validTime" class="text-danger">
Invalid time
</small>
</div>
</div>
제가 주요 형태의 구성 요소로서 "시간"폼 제어 방법을 포함 그래서 this.newForm 통해 값을 액세스 할 .controls [ '시간']. 값 ??
이 부모와 자식입니까? – Alex
@ AJT_82 예 .. 부모님과 자식입니다 – sam1990