angularjs - UI-bootstrap datepicker ng-model $scope data not correct in controller -
i'm trying use ui bootstraps datepicker let user select date. selected information asume stored in ng-model $scope.enddate variable. after date picked, correct information displayed in browser debugging section above.
view
<pre> ---------- debugging: {$ modelstartdate $} {$ !!partners.length $} chosen stardate: {$ startdate.getdate() $} of {$ startdate.getmonth() $} chosen end-date: {$ enddate.getdate() $} of {$ enddate.getmonth() $} chosen current year {$ enddate.getfullyear() $} </pre> <input ng-click="openstartendpicker($event, 'secondcal')" type="text" class="form-control" datepicker-popup="yyyy/mm/dd" ng-model="enddate" is-open="modelenddate.secondcal" name="secondcal" max-date="'2015-06-22'" datepicker-options="dateoptions" date-disabled="disabled(date, mode)" ng-required="true" close-text="close" datepicker-mode="month"/> <button ng-click="findnotlinkedpartners()" type="submit" class="btn btn-info"> <span><i class="glyphicon glyphicon-repeat"> validate</i></span> </button>
on ng-click event, want use data make post request. default information 2015 - 4 in console??
controller:
//datepicker (selfenvoicing) $scope.startdate =''; $scope.enddate =''; //set start end end date based on current day $scope.initdates = function() { var date = new date(); $scope.startdate = new date(date.getfullyear(), date.getmonth(), 1); $scope.enddate = new date(date.getfullyear(), date.getmonth() + 1, 0); //do initial partner validatioin year/month information (selve invoiking function) }(); //in-calender functions/options $scope.today = function() { $scope.dt = new date(); }(); $scope.toggleweeks = function () { $scope.showweeks = ! $scope.showweeks; }; $scope.clear = function () { $scope.dt = null; }; $scope.togglemin = function() { $scope.mindate = ( $scope.mindate ) ? null : new date(); }(); $scope.dateoptions = { 'year-format': "'yy'", 'starting-day': 1 }; //trick prevent not opening calender next time $scope.modelenddate = {}; $scope.openstartendpicker = function($event, elementopened) { $event.preventdefault(); $event.stoppropagation(); $scope.modelenddate[elementopened] = !$scope.modelenddate[elementopened]; };
function called:
$scope.findnotlinkedpartners = function() { console.log($scope.enddate.getfullyear() + " - " + $scope.enddate.getmonth()); // post request here };
you can call function on ng-change on input element , send 'this' variable, able access scope of directive. using can set controller models :-) happy coding
Comments
Post a Comment