Reputation: 527
I'm new to angularjs, I would like to show either "before", "during" or "after" in {{here}} as shown below:
<td md-cell>{{here}}</td>
<td md-cell>{{a.StartDate}} ~ {{a.EndDate}}</td>
The StartDate and EndDate are retrieved from SQL database and both are working without any problems.
I have written something like the code below trying compare the date, I'm not sure if meets angularjs' grammar and I would like to have the return values shown in {{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";
}
How can I connect them together?
Upvotes: 1
Views: 47
Reputation: 138
Either change your function call to :
<td md-cell>{{vm.checkStatus(a.StartDate, a.EndDate)}}</td>
<td md-cell>{{a.StartDate}} ~ {{a.EndDate}}</td>
Or your function to :
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";
}
And a var declaration / initialization
public var here = "Invalid"
Upvotes: 2