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

1 Answer 1

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

Sign up to request clarification or add additional context in comments.

3 Comments

didn't work , should i change anything in input tag ?
element in angular is Jquery object. Try to remove $(function () {
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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.