datepickerangular-ui-bootstrap

Angular UI-Bootstrap how to get date from DatePicker?


Given the pop-up example at http://plnkr.co/edit/idrirF9zxvCMCQWTk8nr?p=preview how do I actually get the date if the user changes it?

I am guessing that I should do it in $scope.open = function($event) but I just don't know how. I have searched this site & googled extensively. What did I miss?


Solution

  • I think maybe your miss ng-model, ng-model is the way to do two-way data binding in Angular.

    For example:

    <input type="text" datepicker-popup="dd-MMMM-yyyy" ng-model="dt" />
    

    In this example date is binding to dt (ng-model="dt") you can get data by $scope.dt. If you want to watch the date change you can do:

    $scope.$watch('dt',function(val){
       //to do       
       console.log(val)
    })