请看小提琴:https://jsfiddle.net/ThiagoRomam/1hyguh6n/
$scope.setDates = function(initialDate, finalDate) {
$scope.initialDate = initialDate;
$scope.finalDate = finalDate;
$scope.apply();
};
当您按下输入中的任意键或单击选项(所有时间,今天)时,将在完成绑定之前调用 apply 方法。
我该如何解决?
答案 0 :(得分: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();
});
Do not use function name like apply
, in case mix with the built-in function $apply
.