0

I have Following Directive , how can i implement ng-change with it . the directive is working but ng-change only works when i manually change value of text box not when i change it using date picker

 app.directive('datepicker', function () {
    return {
        restrict: 'A',
        require: 'ngModel',
        link: function (scope, element, attrs, ngModelCtrl) {

            $(function () {


                element.persianDatepicker({
                    formatDate: "YYYY/0M/0D",
                    onSelect: function (date) {
                        scope.$apply(function () {
                            ngModelCtrl.$setViewValue(date);
                        });
                    }
                });
            });
        }
    }
}); 

and in my HTML

 <input datepicker type="text" id="EndDate" ng-model="Filter.EndDate" class="form-control" ng-change="DateSelect()" />

DateSelect() only runs when i change value of text box manually

Arash
  • 3,458
  • 7
  • 32
  • 50

1 Answers1

1

Edited

ng-change is directive only for user input. Try to use $watch instead. Here are good answers:

Angular - ng-change not firing when ng-model is changed

When to use $watch or ng-change in Angularjs

Community
  • 1
  • 1
  • didn't work , should i change anything in input tag ? – Arash Jan 26 '16 at 07:51
  • `element` in angular is Jquery object. Try to remove `$(function () {` – Kovalenko Ivan Jan 26 '16 at 08:00
  • thanks for your answers , but i finally used bootstrap datepicker and i works , the problem is with jquery date picker because even with jquery event change binding , it doesnt do anything. – Arash Jan 26 '16 at 09:05