K
K
KOPC18862016-06-14 11:57:21
JavaScript
KOPC1886, 2016-06-14 11:57:21

Why does the function in the directive fire 2 times instead of 1?

Hello!

There is a directive for changing the value of an input, but it works for changing not a specific input, but any other. Why is that?

Here is an example Example

Thanks in advance!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
K
KOPC1886, 2016-06-14
@KOPC1886

If you write like this in the directive, it only works when the required input changes

DirectivesApp.directive('calendarChange', ['$document', '$timeout', function($document, $timeout) {
        return {
            restrict: 'AE',
            link: function(scope, element, attrs) {
                $timeout(function() {
                    var $inputCalendar = document.getElementById('blockCalendar').getElementsByClassName('calendar_input');
                    angular.element($inputCalendar).on('change', function() {
                        console.log(scope.item);
                    });
                    /*$inputCalendar.on('change', function() {
                        console.log(scope.item);
                    });*/
                }, 500);
            }
        };
    }]);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question