1

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?

3
  • you don't need to use $scope.apply(); there Commented Jul 28, 2015 at 15:15
  • The apply() is not $apply: scope: { ... apply: "&fApply" } Commented Jul 28, 2015 at 16:10
  • Although it wasn't the same method. It's good to know that I could be overriding wrongly an Angular method. Commented Jul 28, 2015 at 16:50

1 Answer 1

1

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.

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

1 Comment

it works! :D Also I rename the method in the initial scope to "applyMethod" and create a new "apply" method during linking using your suggestion. This way, calls made direct in html to "apply" will wait the $diggest too

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.