I am using the datepicker from bootstrap-UI for angular. I would like to toggle between two functions. now() and clear(). Is this possible inside Angular's ng-click?
http://plnkr.co/edit/aMcKwXOSQwgnGwfNN9yI?p=preview
The toggle has the ng-click="today()" I would like to add clear() to it, thanks.
Controller Code:
$scope.today = function() {
$scope.dt = new Date();
};
$scope.today();
$scope.clear = function () {
$scope.dt = null;
};
Edit - I saw this answer but I would like to explore all options.
You can create a
toggle()function which will call the function you want based on a variable tracking the state. You can then simply use this function in your template asng-click="toggle()".Something like this.
A shorter version
But if
clear()andtoday()are no longer called in the template I would suggest taking them out of$scope.