Working with angular 7 and Bootstrap 4, I want to wrap my bootstrap 4 inputs in a custom component in order to reduce the boilerplate in my templates.
I want that the final main component look like:
<form [formGroup]="myForm" (submit)="submit(myForm.value)">
<app-form-control label="Lastname" placeholder="Lastname" formControlName="lastName"></app-form-control>
<app-form-control label="Firstname" placeholder="Firstname" formControlName="firstName"></app-form-control>
<button class="pull-right" type="submit">
SUBMIT
</button>
<button (click)="reset()">
RESET
</button>
</form>
Where my formGroup is created like this:
public createFormGroup() {
return this.fb.group({
firstName: [null, Validators.required],
lastName: [null, Validators.required],
});
}
The template of app-form-control should look like this:
<div class="form-group row">
<label class="col-2 col-form-label">{{label}}</label>
<div class="col-10">
<input class="form-control" placeholder="{{placeholder}}" [formControlName]="formControlName" autocomplete="nope"/>
</div>
</div>
But I don't know how to write the component (in TypeScript). How do I bind the outer formControlName attribute to the inner input field? How to make validation work?