1

Have used this code which invokes the user defined function : getTooltipText

<i tooltip=\"{{ getTooltipText(arg1) }}\"> </i>
....

//function definition

$scope.getTooltipText = function(arg1){
console.log(arg1); // prints undefined
....
return text;
}

But it is not working. Have even tried trinary operator, but no luck!! Any suggestion?

1
  • Can you explain what are you trying to achieve with arg1? arg1 must be defined in your scope to be able to pass it as a parameter, tooltip will not pass it. Commented Apr 15, 2014 at 13:14

1 Answer 1

3

instead of {{ getTooltipText(arg1) }} ,may be you can use ngMouseenter and ngMouseleave directive.

<div ng-mouseenter="getTooltipText(arg1)">     
    <i tooltip="{{tooltip}}"></i>
</div>  

In your controller:

$scope.getTooltipText = function(arg1){
   $scope.tooltip = "Your tooltip here";
}  

link
(I am not sure about usage of arg1)

I took code from angular site and modified it a little just to demonstrate working of it:

   <body ng-app="" ng-controller="controller">
   <button ng-mouseenter="mouseOvver()" ng-mouseleave="mouseLeave()">
   when mouse enters
 </button>
 count: {{msg}}

 <script type="text/javascript">
 function controller($scope)
 {
   $scope.mouseOvver = function()
   {
     $scope.msg="Ok I got u";
   }
   $scope.mouseLeave = function()
   {
     $scope.msg="";
   }
 }
 </script>
</body>
Sign up to request clarification or add additional context in comments.

1 Comment

ng-init should only be used to run specific code that requires properties on the scope only available inside the context of the element. For example ng-repeat has a special property called $index but you might want to use it inside another scope. For more info check docs: docs.angularjs.org/api/ng/directive/ngInit

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.