Search code examples
angularjsangular-bootstrap

How to detect when a date is selected in Angular Bootstrap datepicker


I'm using the datepicker directive in Angular Bootstrap like so:

<datepicker ng-model="period_start" show-weeks="false" class="bs-dateselector"></datepicker>

How can I detect when a user has actually selected a date?


Solution

  • Exactly as you would detect that a user has typed into an <input ng-model="foo"> (with ng-model) - by using ng-change:

    <datepicker ng-model="period_start" show-weeks="false" class="bs-dateselector"
                ng-change="dateChanged()"></datepicker>
    

    That's the idea behind the ngModel directive - that other directives that require: "ngModel", like ng-change or various validators do not need to make any assumptions about the underlying DOM of the input control.