Javascript ng开关在ng重复内,无错误,但不工作
我正在尝试建立一个基本的图像库,这样我可以将currentImage更改为某个数字,并显示具有该数字的图像 这是我的html:Javascript ng开关在ng重复内,无错误,但不工作,javascript,angularjs,angularjs-directive,Javascript,Angularjs,Angularjs Directive,我正在尝试建立一个基本的图像库,这样我可以将currentImage更改为某个数字,并显示具有该数字的图像 这是我的html: <div class="main_image" ng-switch on="current_image"> <img ng-repeat="image in sorted_images" ng-src="{{ image.large }}" class="image {{ $index }}" ng-switch-when="{{ $index
<div class="main_image" ng-switch on="current_image">
<img ng-repeat="image in sorted_images" ng-src="{{ image.large }}" class="image {{ $index }}" ng-switch-when="{{ $index }}">
<img ng-src="{{ sorted_images[0].medium }}" class="image 0" ng-switch-default >
</div>
虽然我的控制器肯定在更新当前的_image变量,但似乎没有发生切换。这可能是因为$index?不确定?是否可以像我在上面的例子中所做的那样在ng repeat中使用ng开关
谢谢 如果您使用控制器设置了
当前_图像
,并且希望显示相应的图像,那么您只需要使用
<img src="{{ sorted_images[current_image].large }}" class="image {{ current_iamge }}" />
更简单的解决方案,谢谢!只是想知道,您知道我的其他代码不起作用的原因吗?您不需要为此使用switch,您应该使用ng repeat和ng show=“current_image==$index”来完成。如果您使用ng指令,那么您不需要使用{{},您应该使用$index来完成。但我不确定这样做是否正确。
<img src="{{ sorted_images[current_image].large }}" class="image {{ current_iamge }}" />