所以基本上就是标题。我正在用AngularJS 1.5和TypeScript2.3编写一个Todo WebApp。我需要的一个“特性”是:如果你的TodoTask的日期是相对于今天的过去,它应该是红色的。它的工作方式应该是这样的。但是,一旦我重新加载页面,颜色就会恢复为默认颜色。所以我的问题是,有没有一种方法可以让它在重新加载后重新评估,或者以某种方式坚持下来?我使用localStorage,顺便说一句。
我尝试过ng样式和ng类。所以只有ng类起作用了。除了重新加载的问题。
<table class="table table-striped table-dark">
<tr ng-repeat="todo in todo">
<td>
<input type="checkbox" ng-model="todo.done" ng-change="save()" />
<span ng-class="{'done': todo.done}"> {{todo.title}} </span>
<br><br>
<span ng-class="{'older' : isPassed(todo.date)}"> {{todo.date | date: "dd-MM-yyyy"}} </span>
<button type="button" ng-click="delete($index)" class="close" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</td>
</tr>
</table>CSS
.older {
color: red;
}The main.ts
$scope.isPassed = function(date) {
return date < $scope.today;
}发布于 2019-09-14 02:23:20
要获得预期结果,请使用下面在$onInit方法中使用$scope.isPassed方法选项
$onInit(){
$scope.isPassed = function(date) {
return date < $scope.today;
}
}https://stackoverflow.com/questions/57928494
复制相似问题