我正在更新服务回调中$scope
的值。回调会执行,但绑定的更新不会反映在视图中。
控制器:
$scope.changeStartDateOk = function(){
UserService.changeStartDate($scope.startDateSelected.value, function(){
$scope.startDate = $scope.startDateSelected.value;
console.log('callback called');
});
};
查看:
<div><p class="left">Start date</p><p class="right">{{startDate | formatDateLong}}</p><div style="clear: both;"></div></div>
我已尝试$scope.$digest()
和$scope.apply()
无济于事。这是由于视图上是否存在过滤器引起的?
过滤器:
angular.module('myApp', []).filter('formatDateLong', function() {
return function(input) {
var date = new Date(input);
if(isNaN(date.getTime())) {
return 'N/A';
}
return date.getDate() + '-' +
['January',
'February',
'March',
'April',
'May',
'June',
'July',
'August',
'September',
'October',
'November',
'December'][date.getMonth()] + '-' +
date.getFullYear();
};