I am using https://github.com/alongubkin/angular-datepicker in an ionic app becuase I dont want to add jQuery as I would only be using it for the calendar.
I have defaulted the date to today's date in my controller and I am trying to bind to the date selected in the calendar but it doesn't update the selectedDate...
<input type="button" class="button" pick-a-date="selectedDate" data-ng-model="selectedDate"/>
My controller looks like this:
var myApp = angular.module('myApp',['angular-datepicker']);
function MyCtrl($scope, $rootScope) {
$rootScope.selectedDate = new Date();
}
If I dont default to today - the scope is still not updated when someone chooses a date
You need do:
function MyCtrl($scope, $rootScope) {
$scope.selectedDate = new Date();
}
Your model isn´t generated in $rootScope. In ng-model documentation you can see
Note: ngModel will try to bind to the property given by evaluating the expression on the current scope. If the property doesn't already exist on this scope, it will be created implicitly and added to the scope.
I suposse that your MyCtrl is attached in view (< html ng-controller="MyCtrl" >).
Also, you can use $rootScope but I do not recommend it.
Good luck!