Thiago Romam
Thiago Romam

Reputation: 439

AngularJs binding is delaying in directive

Please see the fiddle: https://jsfiddle.net/ThiagoRomam/1hyguh6n/

$scope.setDates = function(initialDate, finalDate) {
    $scope.initialDate = initialDate;
    $scope.finalDate = finalDate;
    $scope.apply();
};

When you press any key in the input or when you click the options (All Time, Today), the apply method is called before the binding can be done.

How can I fix that?

Upvotes: 1

Views: 33

Answers (1)

Joy
Joy

Reputation: 9550

Add the $timeout to wait for the $digest to finish. Check working demo: JSFiddle

app.directive("dateFilter", ['$timeout', function ($timeout) {
    ...
    $timeout(function () {
        $scope.apply();
    }); 

Suggestion

Do not use function name like apply, in case mix with the built-in function $apply.

Upvotes: 1

Related Questions