Change class on mouseover in directive

前端 未结 4 1844
醉梦人生
醉梦人生 2020-12-12 19:31

I am having trouble working out how to get a class to change on a nested directive.

This is the outer ng-repeat

4条回答
  •  自闭症患者
    2020-12-12 20:17

    In general I fully agree with Jason's use of css selector, but in some cases you may not want to change the css, e.g. when using a 3rd party css-template, and rather prefer to add/remove a class on the element.

    The following sample shows a simple way of adding/removing a class on ng-mouseenter/mouseleave:

    Test 1 2 3.

    with some styling:

    .red {
      background-color: red;
    }
    
    .italic {
      font-style: italic;
      color: black;
    }
    

    See running example here: jsfiddle sample

    Styling on hovering is a view concern. Although the solution above sets a "hover" property in the current scope, the controller does not need to be concerned about this.

提交回复
热议问题