I'm trying to reduce code repetition in my code base, where I have the following pattern in my HTMLs:
<card-component>
<card-header>{{entityFormName}}</card-header>
<card-body>
<form (ngSubmit)="onSubmit()" id="formId" [formGroup]="entityForm">
<!-- <ng-content></ng-content> -->
<!-- Here I have a bunch of custom form content/formatting -->
</form>
</card-body>
<card-footer>
<!-- button outside of form -->
<button type="submit" form="formId" [disabled]="entityForm.invalid || loading">{{submitButtonText}}</button>
<!-- loading icon spinner -->
</card-footer>
</card-component>
basically, I have several CRUD-type forms that follow this pattern, and I want to keep it all in a separate component so reduce repetition. I have an abstract component-like class that implements onSubmit()
, creates entityForm
and controls loading
. The classes that extend from this abstract class will also implement some custom behavior for their own forms.
The thing is: how do I send the entityForm
to whatever component is implementing this form, so that I can actually create it? Is it even possible?
Alternatively, am I approaching this the wrong way? Perhaps there's a better/different pattern to follow in order to reduce code repetition here?
Thank you in advance.