AngularJs 绑定在指令中延迟

AngularJs binding is delaying in directive

请参阅fiddle:https://jsfiddle.net/ThiagoRomam/1hyguh6n/

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

当您在输入中按任意键或单击选项(所有时间、今天)时,apply 方法会在绑定完成之前被调用。

我该如何解决?

添加$timeout等待$digest完成。检查工作演示:JSFiddle

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

建议

不要使用apply这样的函数名,以免与内置函数$apply.

混用