1

It seems that numeric values initiated using ng-init works with CSS attribute as seen on the sample using myHeight variable.

However, the variable event doesn't seem to work. Even with the value set to none, the hover effect is still triggered when hovered in the element:

.has-hover {
  background-color: red;
}

.has-hover:hover {
  background-color: green;
}
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>


<div ng-app ng-init="myHeight=100; event=none">
  <div class="has-hover" style="height: {{myHeight}}px; pointer-events: {{event}};" >
  </div>
</div>

2 Answers 2

2

You should use ng-style for this. Also, I think you need to set event equal to the string 'none':

.has-hover {
  background-color: red;
}

.has-hover:hover {
  background-color: green;
}
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>

<div ng-app ng-init="myHeight=100; event='none'">
  <div class="has-hover" ng-style="{ height: myHeight + 'px', 'pointer-events': event }">
  </div>
</div>

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

Comments

1

You should use ng-style like this

ng-style="{'height': myHeight + 'px','pointer-events':event}"

Comments

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.