javascript - 如何在 angular.js 中调用 ng-title 属性上的作用域函数

标签 javascript angularjs scope attributes

这是我的 html 代码

 <td ng-title="tileOfAbsent(this.attendance.absent)" ng-  
  style="IsAbsOrPres(this.attendance.absent)" style="color: red">  
  {{attendance.absent}}</td>

这是 Controller

 $scope.tileOfAbsent = function (value) {
            var title1= "Absent";
            var title2= "Present";
            if (value == "AA") {
                return title1;
            }
            else {
                return title2;
            }
        }

 $scope.IsAbsOrPres = function (value) {
        var style1 = { color: "#F41212" };
        var style2 = { color: "#178908" };
        if (value == "AA") {
            return style1;
        }
        else {
            return style2;
        }
    }

问题是tileOfAbsent函数未执行(我已使用断点进行检查)。但 IsAbsOrPres 函数按预期执行。

Why ng-title does not call the function?

最佳答案

我通过使用 title 而不是 ng-title 来获得它

就像,title="{{tileOfAbsent(this.attendance.absent)}}"

<小时/>

这是我完整的工作代码

<td title="{{tileOfAbsent(this.attendance.absent)}}" ng-style="IsAbsOrPres
(this.attendance.absent)" style="color: red">{{attendance.absent}}</td>

关于javascript - 如何在 angular.js 中调用 ng-title 属性上的作用域函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32564383/

相关文章:

javascript - 带有 id 的 ng-route 可以正常工作,但是 json 中带有 id 的 id 是错误的

angularjs - 在grails 2.3.4中加载angularjs

html - 将淡入淡出和滑动(左/上/下/右)与 AngularJS 结合起来

bash - 为什么这个自定义采购函数不能使我声明的变量全局可用?

php - php 是否在 'html body' 之前加载?

javascript - Firefox 问题 - 动态创建的选择元素在表格内不起作用

Javascript:列出同一范围内的所有变量(iframe)

c# - 启动/更新变量范围

javascript - Jquery Ajax 服务器轮询;根据早期的 ajax 响应轮询服务器

javascript - selenium 使用 javascript 定位没有 id 或 name 的元素