我是angularjs的新手,我想在{{here}}中显示“ before”,“ during”或“ after”,如下所示:
<td md-cell>{{here}}</td>
<td md-cell>{{a.StartDate}} ~ {{a.EndDate}}</td>
从SQL数据库检索StartDate和EndDate,它们都可以正常工作。
我已经写了类似下面的代码来尝试比较日期,我不确定是否满足angularjs的语法,我想在{{here}}中显示返回值。
vm.checkStatus = function (var StartDate, var EndDate){
var currentDate = new Date();
if (currentDate < StartDate)
return "Before";
else if (currentDate >=StartDate && currentDate <= EndDate)
return "During";
else if (currentDate > EndDate)
return "After";
else
return "Invalid";
}
如何将它们连接在一起?
答案 0 :(得分:2)
将函数调用更改为:
<td md-cell>{{vm.checkStatus(a.StartDate, a.EndDate)}}</td>
<td md-cell>{{a.StartDate}} ~ {{a.EndDate}}</td>
或您的功能:
vm.checkStatus = function (var StartDate, var EndDate){
var currentDate = new Date();
if (currentDate < StartDate)
this.here = "Before";
else if (currentDate >=StartDate && currentDate <= EndDate)
this.here = "During";
else if (currentDate > EndDate)
this.here = "After";
else
this.here = "Invalid";
}
还有var声明/初始化
public var here = "Invalid"