0

I am trying to change the css property by angularjs when hovering

Here is my code:

$scope.showButtonGroup = () ->
        buttonTools = document.getElementsByClassName('widget-formwidget-topright-actions')
        angular.element(buttonTools).css('display': 'block')

But the console shows me the error that: Referencing DOM nodes in Angular expressions is disallowed! Expression:

Could someone help me on that? thanks!

1
  • Check this. What AngularJS means is to avoid the returning of DOM. Thus return undefined or null in your CoffeeScript. Commented Apr 10, 2014 at 23:53

1 Answer 1

1

you can take advantage of ngStyle directive, where you assign scope variable to change element's style

controller

$scope.changeDisplay = function(value) {
    $scope.displayProperty = value;
}

markup

<div ng-style="{display: displayProperty}" ng-mouseenter="changeDisplay('block')" ng-mouseleave="changeDisplay('none')"></div>
Sign up to request clarification or add additional context in comments.

3 Comments

not a problem, angular has directives also for hovering - ngMouseenter and ngMouseleave where you can define which function it should trigger and in that function change the style
yes, I know, what I am trying to say is, the function (showButtonGroup) is a hovering function, for showing button group when hovering, so why should I use ng-style?
check the edited answer... ngStyle is the correct way of manipulating css styles via angular, that's why you should use it

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.