[英]AngularJS: ng-repeat in directive with isolated scope and $last
我试图抓住$ last属性,以便在ng-repeat完成时收到通知。 我已经为此创建了特殊指令( ngRepeatDoneNotification )。 Ng-repeat适用于另一个元素指令( 单位 )。 因此,有一个带有三个指令的结构:
<unit ng-repeat="unit in collection" ng-repeat-done-notification id="{{unit.id}}"></unit>
一旦我将范围设置为隔离,$ last就会在我的通知程序指令中消失。
App.directive('ngRepeatDoneNotification', function() {
return function(scope, element, attrs) {
if (scope.$last){ // ISSUE IS HERE
window.alert("im the last!");
}
};
});
App.directive('unit', function() {
return {
restrict: 'E',
replace: true,
scope: {id: '@'}, // ONCE I ISOLATE SCOPE, $last DISAPPEARED
templateUrl: '/partials/unit.html',
link: function(scope, element) {}
}
});
我创建了jsFiddle http://jsfiddle.net/4erLA/1/
怎么可能抓到这个?
为了使隔离范围捕获$last
,您需要使用$parent
来引用父范围,如下所示
if (scope.$parent.$last) {
$rootScope[attrs.ngRepeatDoneNotification] = "$last has been catched"
}
您可以重构它以使其适用于两种情况或只是简单地复制它。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.