我想在当前时间等于JSON文件中的时间时隐藏div。但是我找不到正确的方法。您可以使用以下转换器来播放数据:http : //www.epochconverter.com/
而我的代码:
function Ctrl($scope, $timeout) {
$scope.events = [ {
"start_date" : "1288323623006",
"team1" : "FC Dynamo Kiev",
"team2" : "FC Shahtar Donetsk",
"tournaments" : [ {
"tournament_id" : "1"
} ]
}, {
"start_date" : "1416844143000",
"team1" : "FC Dynamo Kiev123",
"team2" : "FC Shahtar Donetsk",
"tournaments" : [ {
"tournament_id" : "1"
} ]
} ];
//Real time clock
$scope.clock = "loading clock..."; // initialise the time variable
$scope.tickInterval = 1000; //ms
var tick = function() {
$scope.clock = Date.now() // get the current time
$timeout(tick, $scope.tickInterval); // reset the timer
};
// Start the timer
$timeout(tick, $scope.tickInterval);
$scope.$watch('clock', function (newVal) {
$scope.clock = newVal;
console.log(newVal);
});
}
</style> <!-- Ugly Hack due to jsFiddle issue: http://goo.gl/BUfGZ -->
<link rel="stylesheet" href="http://twitter.github.com/bootstrap/assets/css/bootstrap.css">
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.0.2/angular.min.js"></script>
<style>
<div ng-app>
<div ng-controller="Ctrl">
<div ng-repeat="event in events" ng-hide="event.start_date == clock">
<h2>{{event.team1}} vs {{event.team2}}</h2>
<p>Starts in: {{event.start_date | date: 'shortTime'}}; Current time: {{clock | date: 'shortTime'}}</p>
</div>
</div>
</div>
看到==会寻找数字相等性,时间可能已经过去并且您的时钟从未==到日期。
尝试时间是否过去,而不是使用<或>进行时间相等
<div ng-repeat="event in events" ng-hide="event.start_date < clock">
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句