所以目前我有一个组件,它有多个按钮可以配置选项:
test.component.html
<button
*ngIf="cleaning"
(click)="onCleaning()"
>
{{'btn.cleaning'|translate}}
</button>
<button
*ngIf="remove"
(click)="onRemoving()"
>
{{'btn.remove'|translate}}
</button>
测试组件.ts
@Input() cleaning: boolean;
@Input() remove: boolean;
cleaningForm: FormGroup;
父组件.html
<test [cleaning]="true" [remove]="false"></test>
想法是这个组件更大并且可以重用,只有按钮和操作会改变,但它总是需要表单。
是否有其他更好的解决方案来获取此类组件,使用 ng-content 并以某种方式在父组件中触发表单?