What the best way to pass ngClass to child component without touch the main component

672 Views Asked by At

I'm looking for the best way to pass ngClass or ngStyle to a subcomponent but without apply to the main component.

For example:

I have a component "button" that I call in app.component.html

<app-button [ngClass]="{'d-none': true}"></app-button>

My component reflects a native button.

export class ButtonComponent implements OnInit {
@Input('ngClass') ngClass: NgClass["ngClass"]
}

<button [ngClass]="ngClass"></button>

My issue in this case is that d-none will apply on the virtual element <app-button></app-button> and not only on the real button element. Because my CSS class d-none is global. Which can cause issue if I want apply this CSS on a specific element of the component.

The only solution I see is to rename ngClass @Input property of the component. But there is maybe a better way to do? A way to not apply ngClass directly on the component maybe?

0

There are 0 best solutions below