使用AngularJS获取'ng-repeat'项的索引(计数器)? [英] Get the index (counter) of an 'ng-repeat' item with AngularJS?

查看:80
本文介绍了使用AngularJS获取'ng-repeat'项的索引(计数器)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用AngularJS及其 ng-repeat 指令来显示一系列问题。我需要以 1 开头的每个问题编号。如何使用 ng-repeat 显示和增加此类计数器?以下是我到目前为止:

I am using AngularJS and its ng-repeat directive to display a sequence of questions. I need to number each question starting with 1. How do I display and increment such a counter with ng-repeat? Here is what I have so far:

<ul>
    <li ng-repeat="question in questions | filter: {questionTypesId: questionType, selected: true}">
        <div>
            <span class="name">
                {{ question.questionText }}
            </span>
        </div>
        <ul>
            <li ng-repeat="answer in question.answers">
                <span class="name">
                    {{answer.selector}}. {{ answer.answerText }}
                </span>
            </li>
        </ul>
    </li>
</ul>


推荐答案

Angularjs文档中充满了示例,您只需要花一些时间探索它。

Angularjs documentation is full of examples, you just need to take some time and explore it.

在此处查看此示例: ngRepeat示例,情况相同。

See this example here : ngRepeat example , it's the same case.

<ul>
    <li ng-repeat="question in questions | filter: {questionTypesId: questionType, selected: true}">
        <div>
            <span class="name">
                {{$index + 1}} {{ question.questionText }}
            </span>
        </div>
        <ul>
            <li ng-repeat="answer in question.answers">
                <span class="name">
                    {{answer.selector}}. {{ answer.answerText }}
                </span>
            </li>
        </ul>
    </li>
</ul>

这篇关于使用AngularJS获取'ng-repeat'项的索引(计数器)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆