call function in angular ui tooltip

↘锁芯ラ 提交于 2019-12-11 12:41:57

问题


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:


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>


来源:https://stackoverflow.com/questions/23083708/call-function-in-angular-ui-tooltip

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!