Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add class to custom component angular 2

Tags:

angular

I have a <myComponent ></myComponent> and I want give class to myComponent?

This doesnt worked `<myComponent class="my-class"></myComponent>` 

How can I do that?

like image 547
emanuel07 Avatar asked May 13 '26 08:05

emanuel07


2 Answers

class MyComponent {
  @HostBinding('class.my-class')
  isMyClass:boolean = true;
}
like image 75
Günter Zöchbauer Avatar answered May 15 '26 20:05

Günter Zöchbauer


Don't think that will work but there are easy workarounds:

If you want to style the placement/color etc of your component:

Best workaround is to place your <myComponent></myComponent> inside a <div> and apply the class to that div

If you want to style the contents of your component:

adding styleUrls in your Component and styling your content with a css file

like image 23
Ivar Reukers Avatar answered May 15 '26 20:05

Ivar Reukers



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!