9

In Angular 1, you could simply add

[ngClick],
[data-ng-click],
[x-ng-click] {
    cursor: pointer;
}

and all tags with the ng-click attribute would now have the pointer cursor now. How can we add the Angular 2 (click) attribute in the same way?

2 Answers 2

6

This is not possible using just the name of an attribute. Angular 2 changes this template:

<div>
    <h2>Hello {{name}}</h2>
    <div (click)="sayhi()"></div>
</div>

to this DOM:

 <div _ngcontent-xwy-0="">
     <h2 _ngcontent-xwy-0="">Hello Angular2</h2>
     <div _ngcontent-xwy-0=""></div>
  </div>

Since there is no way to specify a wildcard attribute name CSS selector (i.e. [_ngcontent-*] { cursor: pointer }, there is no way to achieve this using just CSS.

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

2 Comments

That makes sense. I hope there is some way to work around this in the future.
You can disable view encapsulation. Then it is possible. Not sure that's desired though.
-2

<div href="javascript:void(0)" (click)="sayhi()"></div>

1 Comment

This does not really answer the question; the question is about styling an element that has the (click) pseudo attribute on it, using CSS.

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.