本文介绍了NG-交换机内部AngularJS $指数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图 NG-重复访问 $指数 ,并将其放置在 NG-开关时。 的最后一件事。小块什么,我试图做的:

I am trying to access $index of ng-repeat and place it inside ng-switch-when. Here is the last thing I have tried. Small piece of what I am trying to do:

<li ng-repeat="contact in contacts" ng-switch on="MenuSelected">
 <span ng-switch-when="$index">{{ contact }} {{$index}}</span>
</li>

MenuSelected 我在控制人定义为0,例如,我有测试2个触点。我曾尝试在不同的标签,一切都下跌(只显示线)混合纳克的东西,所以我不认为这是问题。当我删除例如0一切 $指数和地点出现。

MenuSelected I have define in my controller with 0 for example, and I have 2 contacts for test. I have tried to mix ng things in different tags and everything fall (just show lines), so I don't think that is the problem. When I remove $index and place for example 0 everything show up.

推荐答案

您不能使用前pressions与 ngSwitch

you cannot use expressions with ngSwitch

refrer这

请注意,要匹配的属性值,不能前pressions。他们是PTED作为文字字符串值来匹配间$ P $。例如,NG-开关时=someVal会匹配字符串someVal不违背EX pression价值$ scope.someVal

这意味着 NG-开关时=$指数 $指数被视为字符串不作为一个指标值

this implies that ng-switch-when="$index" $index is treated as a string not as a index value

使用ngIf代替

    <span ng-if="$index == MenuSelected">{{ contact }} {{$index}}</span>

下面是工作

这篇关于NG-交换机内部AngularJS $指数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-18 13:35