本文介绍了Angular ui工具提示中的call函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用了此代码来调用用户定义的函数:getTooltipText

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?

推荐答案

代替{{ getTooltipText(arg1) }},也许可以使用ngMouseenterngMouseleave指令.

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

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

在您的控制器中:

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

链接
(我不确定arg1的用法)

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>

这篇关于Angular ui工具提示中的call函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-05 19:25