这是我的 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/