1

I have the following directive

courseApp.directive("courseoverview", function() { 
    function link(scope, element, attrs) {
        scope.switched = false;
        //hover handler
        scope.hoverItem = function(hovered){
        if (hovered) {
            //element.addClass('hover');
            $('#course-'+ scope.$index  +' figure').addClass('tint');
            //console.log(scope.$index);
        }
        else
            //element.removeClass('hover');
            $('#course-'+ scope.$index  +' figure').removeClass('tint');
        };
    }  
    return {    
      restrict : 'A',    
      replace: true,   
      transclude: true,    
      templateUrl: "views/course-overview.html",
      link: link
   }});

The directive is called with the following code

<li data-ng-repeat="item in social" class="social-{{item.name}}" 
                ng-mouseover="hoverItem(true);"
                ng-mouseout="hoverItem(false);"
                current-social="{{item.name}}">

The hover function works great but i need access to this attribute in the directive, well i need the value of it.

Any ideas on how to achieve this would be great.

1 Answer 1

1

First, your directive is named 'courseoverview' but I don't see that attribute anywhere in the markup you provided.

To address your question, you say I need access to this attribute in the directive. But I think you have the attributes in the link function - see the attrs parameter. Those are the attributes on the element that fired your directive.

 function link(scope, element, attrs) { ... } 

See this answer for more.

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

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.