<p id="appt_time" ng-if="x.dateTime | date: MM/dd/yyyy == {{todaysDate}}">DISPLAY IF TRUE{{todaysDate}} </p>
Plunkr:https://plnkr.co/edit/r2qtcU3vaYIq04c5TVKG?p=preview
x.dateTime | date: MM/dd/yyyy
retrieves a date and time which results in being filtered as: 06/18/2016
as per my json file.
My goal is to compare this "x.dateTime" with today's date and display the paragraph if the condition holds true. Hence, in my angular file, I set $scope.todaysDate = "06/18/2016"
, but the paragraph does not appear.
HTML file:
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="style.css">
<script src="https://code.angularjs.org/1.5.5/angular.js"></script>
<script src="script.js"></script>
</head>
<body ng-app="myApp" ng-controller="myCtrl">
<div ng-repeat="x in information">
<!--Compare Json Object to Javascript Object-->
<p ng-if ="x.dateTime">{{x.dateTime | date: MM/dd/yyyy }}</p>
<!--Compare Json Object to Today's Date-->
<p id="appt_time" ng-if="x.dateTime.valueOf() === todaysDate.valueOf()">Open on: {{todaysDate}} </p>
</div>
</body>
</html>
JS File:
// declare a module
var myAppModule = angular.module('myApp', []);
var todaysDate = new Date();
// configure the module.
// in this example we will create a greeting filter
myAppModule.controller('myCtrl', ['$scope','$http', function($scope, $http)
{
$scope.todaysDate = todaysDate;
$scope.test = "Volvo";
$http.get("time.json")
.then(function(data) {
$scope.information = data;
});
}]
);
JSON file:
{
"dateTime":"2016-06-18T18:41:00.748-04:00"
}