2

Which CSS selector to use when applying a style to any component having an event binding?

<button (click)="doSomthing()">click me</button>

Something like this is not working.

[(click)]{
color: red;
}
Amr Eladawy
  • 4,193
  • 7
  • 34
  • 52
  • So, If I understand properly, you would like define css style on click event. I think this [question](https://stackoverflow.com/questions/13630229/can-i-have-an-onclick-effect-in-css) should answer your question. – JTejedor Dec 02 '17 at 13:07
  • No, for any event binding. event custom component with user defined events. – Amr Eladawy Dec 02 '17 at 13:10

1 Answers1

3

In the rendered HTML, there is no attribute that corresponds to the Angular (click) event on the button. You can see that by inspecting the markup with the F12 tool in your browser. Therefore, you cannot use that event binding as a CSS selector. You would have to use another selector to identify the button (id, class, another attribute, etc.).

ConnorsFan
  • 70,558
  • 13
  • 122
  • 146
  • Yes, that is right. That is why I asked this here. I wanted to have one generic rule instead of adding a label (class, directive) to use it as a selector. – Amr Eladawy Dec 02 '17 at 14:02