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;
}
2
  • So, If I understand properly, you would like define css style on click event. I think this question should answer your question. Commented Dec 2, 2017 at 13:07
  • No, for any event binding. event custom component with user defined events. Commented Dec 2, 2017 at 13:10

1 Answer 1

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.).

Sign up to request clarification or add additional context in comments.

1 Comment

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.