不要显示以前的陈述(ng-show)

时间:2017-02-23 16:35:37

标签: javascript html angularjs

我不希望在转到两位作者(或更多)时显示上一个文本。

<span ng-show="stepsdata.authors[0]">
    {{authors[0].surname}} {{authors[1].surname}} ({{year}} 
    <span ng-hide="stepsdata.endPage">p. {{page}})</span>
    <span ng-show="stepsdata.endPage">pp. {{stepsdata.startpage}} - {{stepsdata.lastpage}})</span>

</span>
<span ng-show="stepsdata.authors[1]"> Recent research 
    ({{authors[0].surname}} and {{authors[1].surname}}, {{year}}) suggests that...
</span>
<span ng-show="stepsdata.authors[2]"> Recent research 
    ({{authors[0].surname}}, {{authors[1].surname}} and {{authors[2].surname}}, {{year}}) suggests that...
</span>
<span ng-show="stepsdata.authors[3]"> Recent research 
    ({{authors[0].surname}}, et al., ({{year}}) suggests that...
</span>

如果我只有一位作者,那就很有效。

如果我有两位作者,则会显示ng-show="stepsdata.authors[0]“和ng-show="stepsdata.authors[1]”中的文字,但我只需要显示来自ng-show="stepsdata.authors[1]的文字

如果我有三位作者,则会显示ng-show="stepsdata.authors[0]“和ng-show="stepsdata.authors[1]”以及ng-show="stepsdata.authors[2]“中的文字,但我只需要显示来自g-show="stepsdata.authors[2]的文字}“

在其他情况下也会发生这种情况。 我该如何解决?

1 个答案:

答案 0 :(得分:0)

使用数组的<span ng-show="stepsdata.authors.length == 1"> {{authors[0].surname}} {{authors[1].surname}} ({{year}} <span ng-hide="stepsdata.endPage">p. {{page}})</span> <span ng-show="stepsdata.endPage">pp. {{stepsdata.startpage}} - {{stepsdata.lastpage}})</span> </span> <span ng-show="stepsdata.authors.length == 2"> Recent research ({{authors[0].surname}} and {{authors[1].surname}}, {{year}}) suggests that... </span> <span ng-show="stepsdata.authors.length == 3"> Recent research ({{authors[0].surname}}, {{authors[1].surname}} and {{authors[2].surname}}, {{year}}) suggests that... </span> <span ng-show="stepsdata.authors.length == 4"> Recent research ({{authors[0].surname}}, et al., ({{year}}) suggests that... </span> 属性:

(\d)+