Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/25.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的组件中的索引?_Javascript_Angularjs_Angularjs Ng Repeat - Fatal编程技术网

Javascript 如何访问angularjs中名为ng repeat的组件中的索引?

Javascript 如何访问angularjs中名为ng repeat的组件中的索引?,javascript,angularjs,angularjs-ng-repeat,Javascript,Angularjs,Angularjs Ng Repeat,我有以下文件。这是node-list.html中的代码 <tbody sv-node-list-item ng-repeat="item in items" /> 在节点列表.html中使用此命令(需要将索引发送到节点列表项指令) 最后,您的节点列表项.html将: <tr><td>{{index}}</td></tr> {{index} 有关ng的更多信息,请检查文档和指令变量。trbody和tr不是同一文件的一部分。如果他们是

我有以下文件。这是node-list.html中的代码

<tbody sv-node-list-item ng-repeat="item in items" />

节点列表.html
中使用此命令(需要将索引发送到节点列表项指令)

最后,您的
节点列表项.html
将:

<tr><td>{{index}}</td></tr>
{{index}

有关ng的更多信息,请检查文档和指令变量。

trbody和tr不是同一文件的一部分。如果他们是,我就不会有这个问题。我在其他5或6个地方使用node-list-item.html组件,在这些地方我需要来自具有ng repeat的父级的相同索引。而节点列表项恰好是一个200行代码,我不能在所有这些代码中单独放置places@rexroxmsv节点列表项是一个指令,对吗?你能把你的javascript代码放进去吗?是的,它是一个指令。它为每个迭代附加节点列表项。@rexroxm确定。但是你能将指令中的代码添加到问题中,以便我能更好地帮助你吗?我添加了指令代码如果还有任何东西需要添加,请告诉我。你能创建一个plunker吗?节点列表项指令需要接受索引作为属性。显示该指令的代码我添加了指令代码如果还有任何东西需要添加,请告诉我。
function directive() { return { templateUrl: "partials/node-list-item.html" };}
module.directive("svNodeListItem",[ directive ]);
<tbody ng-repeat="item in items track by $index" sv-node-list-item index="{{$index}}"/>
function directive() { 
    return { 
        scope: {
           index: '@'
        },
        templateUrl: "partials/node-list-item.html" 
    };
}
module.directive("svNodeListItem",[ directive ]);
<tr><td>{{index}}</td></tr>