Jonathan Jones Jonathan Jones - 1 year ago 109
AngularJS Question

AngularJS ng-class not applying css styles

I have a company site that I am developing with AngularJS and I am having some troubles with

ng-class


Here is my HTML:

<a href="timeEntry.php" ng-class="{{(userRole.admin) ? '' : 'inactive'}}">
LINK
</a>


CSS:

.inactive {
pointer-events : none;
cursor : default;
}


Chrome Inspect Element:

<a href="timeEntry.php" ng-class="inactive">
LINK
</a>


Obviously I have tested
class="inactive"
and it is working as it should, Chrome's view source appears to be showing me something that should be working but it is not being applied.

Answer Source

Assuming userRole.admin is a boolean, this should work

<a href="timeEntry.php" ng-class="{ inactive: !userRole.admin }">
    LINK
</a>