Reputation: 159
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
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