Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/21.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript AngularJS:ng repeat in指令,具有独立作用域和$last_Javascript_Angularjs_Angularjs Directive_Angularjs Scope - Fatal编程技术网

Javascript AngularJS:ng repeat in指令,具有独立作用域和$last

Javascript AngularJS:ng repeat in指令,具有独立作用域和$last,javascript,angularjs,angularjs-directive,angularjs-scope,Javascript,Angularjs,Angularjs Directive,Angularjs Scope,我正试图捕捉最后一个在ng repeat结束时通知的属性。我已经为此制定了特别指令(ngRepeatDoneNotification)。Ng repeat适用于另一个元素指令(单位)。因此,有一个结构包含三个指令: <unit ng-repeat="unit in collection" ng-repeat-done-notification id="{{unit.id}}"></unit> 我已经创建了JSFIDLE 如何捕获此项?为了使隔离作用域捕获$last,您需

我正试图捕捉最后一个在ng repeat结束时通知的属性。我已经为此制定了特别指令(ngRepeatDoneNotification)。Ng repeat适用于另一个元素指令(单位)。因此,有一个结构包含三个指令:

<unit ng-repeat="unit in collection" ng-repeat-done-notification id="{{unit.id}}"></unit>
我已经创建了JSFIDLE


如何捕获此项?

为了使隔离作用域捕获
$last
,您需要使用
$parent
像这样引用父作用域

if (scope.$parent.$last) {
    $rootScope[attrs.ngRepeatDoneNotification] = "$last has been catched"
}

您可以重构它,使其在两种情况下都能工作,或者只是简单地复制它。

我认为您不能有这样的动态
id
属性。谢谢,有没有办法检测当前范围是否被隔离,以便在任何情况下都能进行ngRepeatDoneNotification工作?我找到了作用域。$$isolateBindings,但它只在用非空哈希定义作用域时有用。@acidron这是个好问题。我不知道,但您可以尝试检查
范围。$parent.$parent
是否为空,如果为空,则应直接位于控制器的范围内,如果不是,则应位于另一个级别的范围内。
if (scope.$parent.$last) {
    $rootScope[attrs.ngRepeatDoneNotification] = "$last has been catched"
}