所以我对ng-repeat指令有问题。在我的代码中,我有一个父控制器,其数据存储为对象数组。将函数传递给ng-repeat对象
$scope.queue = [
{
name: 'Mark',
sex: 'Male',
age: 21
},
{...}
];
$scope.changePositionInQueue = function (currIndex, targetIndex) {
// move up/down person in queue
};
我想要做的是通过父控制器对我的指令的(“人”)分离范围,并在同一时间可以使用“$索引”功能,“$第一”,“$最后”变量。
<person data-change-position="changePositionInQueue" data-person="person" ng-repeat="person in queue"></person>
指令范围声明:
scope: {
person: '=',
changePosition: '&'
}
的问题是,当我创建NG-REPEAT循环内隔离范围我失去了NG-重复属性。另一方面,当我通过ng-repeat创建默认范围并且我可以访问所有想要的属性时,我不能使用父功能。
所以即使通过那些范围为参数隔离示波器指令 – harishr
感谢您的回答,但我该怎么做?以参数方式传递参数。$ index或$ index在指令子作用域中给我'未定义'。 – tomeks
类似'index:@'在你的指令定义范围内,然后在html'data-index =“$ index”'应该做 – harishr