Angularjs 如何从嵌套的ng repeat中获取值
我的问题是如何在第二次ng重复中获取数据,如下面给出的循环示例所示 例如:Angularjs 如何从嵌套的ng repeat中获取值,angularjs,angularjs-ng-repeat,ng-repeat,Angularjs,Angularjs Ng Repeat,Ng Repeat,我的问题是如何在第二次ng重复中获取数据,如下面给出的循环示例所示 例如: ng-repeat="question in questions" {{$index+1}} ng-repeat="option in question.choiceBeanList" {{questionObj.questionId}} --> Here I have to get both data's 您可以使用ngInit进行此操作 检查文档:如果您只是想获取索引,可以使用$parent.$index
ng-repeat="question in questions"
{{$index+1}}
ng-repeat="option in question.choiceBeanList"
{{questionObj.questionId}} --> Here I have to get both data's
您可以使用ngInit进行此操作
检查文档:如果您只是想获取索引,可以使用$parent.$index Json模型
<div ng-repeat="innerList in list" ng-init="outerIndex = $index">
<div ng-repeat="value in innerList" ng-init="innerIndex = $index">
<span class="example-init">list[ {{outerIndex}} ][ {{innerIndex}} ] = {{value}};</span>
</div>
</div>
嵌套ng重复序列
$rootScope.makes = [
{
name: 'BMW',
models: ['335i', 'M3', 'M4']
},
{
name: 'Mercedes',
models: ['C250', 'E350']
}
];
工作尝试以下方法:
<ul ng-repeat="make in makes">
<li ng-repeat="model in make.models">
({{$parent.$index}},{{$index}}): {{make.name}} {{model}}
</li>
</ul>
希望它能帮助 您可以像这样传递外部ng重复数据
<div ng-repeat="question in questions">
<div ng-repeat="option in question.choiceBeanList">
{{questions.indexOf(question)}} // To get the index value of FIRST ng-repeat
{{$index}} // To get the index value of current ng-repeat
</div>
</div>
使用ng init,如下所述:
<div ng-repeat="question in questions">
<div ng-repeat="option in question.choiceBeanList">
{{questions.indexOf(question)}} // To get the index value of FIRST ng-repeat
{{$index}} // To get the index value of current ng-repeat
</div>
</div>
<div ng-repeat="question in questions">
<div ng-repeat="option in question.choiceBeanList">
{{$parent.$index+1}}_{{$index}}
</div>
</div>