绑定过滤器不更新

时间:2015-02-22 04:14:38

标签: angularjs

我正在更新服务回调中$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();
};

0 个答案:

没有答案