Search code examples
ng-showdate-comparisonng-hide

ng-show/ng-hide based on function call


I'm trying to compare two dates in a controller function and returning true/false to ng-show and ng-hide based on the logic in the controller, but it is not working as expected, below is the plnkr for the same. Can someone please help me figure out what is the issue.

http://plnkr.co/edit/CWvb1uy0PeYFb0Tf34rY?p=preview

var app = angular.module('plunker', []);

app.controller('MainCtrl', function($scope,$filter) {
  $scope.name = 'World';
  $scope.SetDate=function(dt)
  {
    $scope.NewDt=$filter('date')(dt, 'shortDate');
     $scope.currentDate = $filter('date')(new Date(), 'shortDate');   
     $scope.parsedCurr=Date.parse($scope.currentDate);
     $scope.parsedFuture= Date.parse($scope.NewDt);

        if ( $scope.parsedCurr <$scope.parsedFuture) {
            return true;
        }  
  }

});

Solution

  • You are denying twice, you have:

    <span ng-hide="!SetDate('2015-12-31T00:00:00')">
    

    and you need

    <span ng-hide="SetDate('2015-12-31T00:00:00')">