ng-switch中的ng-switch,没有错误,但没有工作

时间:2014-01-18 05:24:49

标签: 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 }}">
    <img ng-src="{{ sorted_images[0].medium }}" class="image 0" ng-switch-default >
</div>

Controller snippet(coffeescript):

main_image = el.find('.main_image');
main_image.on('click', ->
    scope.current_image = 1

似乎虽然我的控制器肯定更新了current_image变量,但是尽管发生了变化,但没有发生切换。可能这是因为$ index?不确定?是否可以像在上面的例子中那样在ng-repeat中使用ng-switch?

谢谢!

1 个答案:

答案 0 :(得分:1)

如果您使用控制器设置了current_image,并希望显示相应的图像,那么您只需要使用

<img src="{{ sorted_images[current_image].large }}" class="image {{ current_iamge }}" />
相关问题