一些问题:
当角指令处理,你通常不需要使用{{...}}
语法,只需使用真正值。因此,而不是:
data-ng-click="sw='{{test.name}}'"
使用:
data-ng-click="sw = test.name"
(见为什么这是不够的下一个点)
ng-repeat
使用它自己的范围与transclusion,所以以上将sw
设置在错误的范围内,使用:
data-ng-click="$parent.sw = test.name"
你不能ng-repeat
建立ng-switch-when
的,尽量ng-show/hide
而不是尝试:
<div ng-repeat="test in tests" ng-show="sw == test.name">
演示:http://jsbin.com/uxobot/1/
但所有的一切,我没有看到在第二个div上需要ng-switch/ng-repeat
。下面有同样的效果,可能是更大量的语义:
<div ng-controller="MyCtrl">
<div class="click">
<div ng-repeat="test in tests" data-ng-click="$parent.active = test">
{{test.name}}
</div>
</div>
<div class="switch">
{{active.text}}
</div>
</div>
演示:http://jsbin.com/elufow/1/
非常感谢,这正是我需要的! :) – Sylla