I have developed a custom dateTime component for my application. I am currently facing an issue where I need to integrate this component within a formGroup in a separate component. Despite several attempts, I am unable to display the data from the child form within the parentForm. Is there any way to set this as a property or value of the parent form?
Child DateTime Picker HTML:
<mat-form-field>
<input matInput [ngxMatDatetimePicker]="picker" placeholder="{{ name }}" [formControl]="dateControl" required="true">
<mat-datepicker-toggle matSuffix [for]="picker"></mat-datepicker-toggle>
<ngx-mat-datetime-picker #picker startView="year"></ngx-mat-datetime-picker>
</mat-form-field>
Child Typescript:
@Input() name: string;
@Input() displayTime: boolean;
@Input() allowDateInPast: boolean;
public dateControl = new FormControl();
constructor() { }
ngOnInit() {
}
Parent HTML/form:
<form [formGroup]="formGroup">
<mat-label>Name</mat-label>
<input type="textfield" formControlName="reportName" matInput required="true" placeholder="Report Name" name="reportName">
</mat-form-field>
<div class="col-sm">
<app-datetime-picker [name]="'Start Date'" [displayTime]="true" [allowDateInPast]="true"></app-datetime-picker>
</div>
<button class="float-right" [disabled]="formGroup.invalid" (click)="createReport()" mat-raised-button color="primary">Save</button>
</div>
</form>
Parent Typescript:
formGroup: FormGroup = new FormGroup({
reportName: new FormControl("", Validators.required),
// ?? something here
});
Is it feasible to achieve this? Do I need to utilize @Output() in some way?
Appreciate any assistance.
Travis W-