我正在比较时间,并基于此设置 css 类名,但我犯了一些错误,这就是代码不起作用的原因。请任何人看到我的代码并告诉我我在哪里犯了错误。
<div ng-app="app" ng-controller="ctrl" class="panel-group" id="accordion">
<ul class="nav nav-pills" ng-init="catVal = 1">
<li ng-repeat="item in products" ng-class="{'css-class-yellow' : moment($scope.dbTime, 'HH:mm:ss').diff(moment(item.businessTime, 'HH:mm:ss'), 'minutes') > 60,'css-class-red' : moment($scope.dbTime, 'HH:mm:ss').diff(moment(item.businessTime, 'HH:mm:ss'), 'minutes') > 200, 'css-class-green' : moment($scope.dbTime, 'HH:mm:ss').diff(moment(item.businessTime, 'HH:mm:ss'), 'minutes') > 300 }">
<a href="">{{item.name}}</a>
</li>
</ul>
</div>
var app = angular.module("app",[]);
app.controller("ctrl" , function($scope){
$scope.dbTime='12:05:05';
$scope.products = [{
'name': 'Xbox',
'clearance': true,
'price': 30.99,
'businessTime':'04:15:22'
}, {
'name': 'Xbox 360',
'clearance': false,
'salesStatus': 'old',
'price': 99.99,
'businessTime':'12:10:22'
}, {
'name': 'Xbox One',
'salesStatus': 'new',
'price': 50,
'businessTime':'06:25:22'
}, {
'name': 'PS2',
'clearance': true,
'price': 79.99,
'businessTime':'08:11:22'
}, {
'name': 'PS3',
'salesStatus': 'old',
'price': 99.99,
'businessTime':'17:41:22'
}, {
'name': 'PS4',
'salesStatus': 'new',
'price': 20.99,
'businessTime':'21:05:22'
}];
});
.css-class-yellow{
background-color: yellow;
}
.css-class-red{
background-color: red;
}
.css-class-green{
background-color: green;
}