krishna teja
krishna teja

Reputation: 159

How to show a timestamp on a checkbox selection using angular?

I was trying to figure out how to show the timestamp when we check the checkbox and it should disappear when we uncheck. Could some one please help me how to do that in angular? Thanks

Upvotes: 0

Views: 300

Answers (1)

devadrion
devadrion

Reputation: 216

You could do following

HTML

<input
    type="checkbox"
    name="mycheckbox"
    value="{{time}}"
    ng-model="isChecked"
  > {{time}}

Angularjs Controller

$scope.isChecked=false;


  $scope.$watch('isChecked', function() {
        if($scope.isChecked){
           $scope.time=Date.now().getTime();
        }else{
           delete $scope.time;
        }
    });

Upvotes: 1

Related Questions