【发布时间】:2014-07-25 09:29:51
【问题描述】:
我正在使用 angular、bootstrap 和一个名为“ui-bootstrap”的插件来制作旋转木马。
我有一个缩略图列表,当单击其中一个时,会显示一个带有旋转木马内高清图像的模式,类似于您在亚马逊或其他网站上的内容。我试图将轮播中显示的第一个图像设置为用户单击的图像。
我已经能够使用 $index 获取图像的索引,因为我在 ng-repeat 中,将它提供给模态控制器并毫无问题地显示轮播。但是第一张图片的索引总是 0,即使我尝试设置我拥有的索引。
这些是我尝试过的一些事情:
$scope.SliderItems = items; // This one sets the items in the slider array
items[selectedIndex].active = true;
$scope.SliderItems[selectedIndex].active = true;
$scope.SliderItems.select(SliderItems[selectedIndex]);
我还尝试在一个属性上设置它,在所需项目上将“活动”属性设置为 true,但随后它在该项目上被阻止,导致轮播崩溃。另外,在轮播元素上尝试了属性“data-slide-to”,但没有成功。
$scope.SelectedIndex = selectedIndex;
所以我不知道要使用哪个属性/方法来执行此操作,并且插件页面上的文档也没有给我更多的指示:(
http://angular-ui.github.io/bootstrap/
有谁知道如何设置默认的活动幻灯片?甚至在加载后如何设置它,因为在底部有一个带有缩略图的轮播可能很有用,您可以单击它来显示主图像或其他内容。
谢谢。
已解决
我以前尝试过这样的事情,但没有成功,但是用不同的方法再次尝试,这次我成功了。所以,在控制器上设置 .active=true 后,这就是 HTML:
<carousel>
<slide ng-repeat="item in SliderItems" active="item.active">
...
</slide>
</carousel>
以防万一,控制器:
$scope.SliderItems = items; // items comes from another controller with the items
$scope.SliderItems[selectedIndex].active = true; //selectedIndex also comes from the other controller
【问题讨论】:
-
谢谢,正如我所说的,我已经尝试过这个,但只是为了向您展示我再次尝试过的代码,这次成功了。也许我上次没有做对。
标签: javascript angularjs carousel angular-ui-bootstrap