Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to apply cursor-pointer property to (click) event handler?

Tags:

css

angular

<i class="cursor-pointer" (click)="sort()"></i>

Our codebase has a lot of redundant classes like this. I was looking for a way to apply the cursor pointer property anytime there is a (click) event handler.

Before angular 2, you were able to apply css to angular attributes, but that is no longer possible. Change the mouse pointer on ngclick

[ng-click]{
    cursor: pointer;
}
like image 652
Garet Webster Avatar asked Nov 05 '19 17:11

Garet Webster


People also ask

Which CSS property can you use to change the cursor style on the hover mouse event?

Answer: Use the CSS cursor Property.


1 Answers

You can create a directive that selects all the elements with click binding and apply the style.

click.cursor.directive.ts:

@Directive({
  selector: '[click]'
})
export class ClickCursorDirective {
  @HostBinding('style.cursor') cursor: string = 'pointer';
}

app.component.html:

<div (click)="onClick()">Button</div>

Here is a Stackblitz demo

like image 173
talhature Avatar answered Oct 19 '22 03:10

talhature