我被阻止了角度双向绑定和过滤器的问题。我使用参数过滤器,并在另一个指令中更改参数值后,不应用过滤器。以下是代码的一部分:
<div class="col-md-offset-4 col-md-4">
<calendar-select ng-model="dailyTimekeepingCtrl.selectedDay"> </calendar-select>
</div>
.......
<work-timekeepings-day timekeepings="dailyTimekeepingCtrl.timekeepingList"
day="dailyTimekeepingCtrl.selectedDay"></work-timekeepings-day>
组件定义:
var workTimekeepingsDay = TimekeepingsApp.component('workTimekeepingsDay', {
templateUrl : 'angular/components/work-timekeepings-day.html',
controllerAs: '$workTkDayCtrl',
bindToController: true,
controller: function() {
this.isTkCollapsed = true;
this.workTimekeepingTemplate='angular/popups/work-timekeeping-popup.html';
},
bindings : {
timekeepings : '=',
day: '='
}
});
组件模板:
<p> {{($workTkDayCtrl.timekeepings | workTimekeeping : $workTkDayCtrl.day).length }} </p>
<p> {{$workTkDayCtrl.day | amDateFormat:'DD MM YYYY'}}</p>
dailyTimekeepingCtrl.selectedDay
使用指令进行更改,与其双向绑定:
var calendarSelect = TimekeepingsApp.directive('calendarSelect', ['$timeout', function($timeout) {
return {
restrict : 'E',
scope : {
calendarDate : '=ngModel'
},
templateUrl : 'angular/calendar-select.html',
link: function (scope, element, attrs) {
scope.dayUp = function() {
scope.calendarDate.add(1, 'days');
};
...................
第一次触发时,会正确应用过滤器。在父页面/控制器中更改dailyTimekeepingCtrl.selectedDay
后,正确应用了day
绑定变量。但结果不会被新值过滤。谁能暗示我做错了什么?
感谢。