Javascript 角度UI引导转盘获取活动幻灯片对象

Javascript 角度UI引导转盘获取活动幻灯片对象,javascript,angularjs,angular-ui-bootstrap,angular-ui,Javascript,Angularjs,Angular Ui Bootstrap,Angular Ui,我正在尝试从角度UI引导转盘中的幻灯片阵列获取活动幻灯片对象: 我当前的解决方案: app.controller('myContr', ['$scope', '$http', 'filterFilter', function($scope, $http, filterFilter) { $scope.b = {}; $scope.b.int = 5000; $scope.b.active = 0;

我正在尝试从角度UI引导转盘中的
幻灯片阵列
获取
活动幻灯片对象
: 我当前的解决方案:

app.controller('myContr', ['$scope', '$http', 'filterFilter',  function($scope, $http, filterFilter) {
            $scope.b = {};
            $scope.b.int = 5000;
            $scope.b.active = 0;

            var banners = [
                {
                    "delay": 5,
                    "position": "top",
                    "background": "img_url",
                },
                {
                    "delay": 5,
                    "position": "top",
                    "background": "img_url",
                }
            ];
            var b = $scope.b.banners = filterFilter(banners, {
                position: 'top'
            });
            $scope.$watch('b.active', function(active) {
                $scope.b.int = parseInt(b[active]['delay'])*1000;
            });

        }]);
HTML:


bootstrap UI允许设置幻灯片的
活动索引
,因此我使用
$watch
来确定活动幻灯片,但我在源代码中看到,在该幻灯片上已经有一个
$watch

我的问题是,是否有其他解决方案可以在不使用
$watch
的情况下获取活动幻灯片对象


uib幻灯片上有一个
actual
参数,但是找不到关于它的任何文档,因为它使用了什么。

我认为您所做的很好,文档中没有显示任何其他方法。在$watch函数中,您正在根据索引执行计算。如果这就是所有需要做的事情,并且您想要摆脱$watch,那么您可以提前进行计算并将结果存储在数据(
banner)
。在模板中,您可以通过以下方式绑定到间隔:
interval=“banners[b.active].interval”
@SunilD。我只是想要一个完整的幻灯片对象,在幻灯片更改时,因为现在我在控制器内部进行过滤,但如果我在html中进行过滤,
$index
可以与数组键不同。但是,是的,您的解决方案适用于更改每张幻灯片的间隔。
<body ng-controller="myContr">
    <div uib-carousel interval="b.int" active="b.active">
        <div uib-slide ng-repeat="ban in b.banners track by $index" index="$index">
            <img ng-src="{{ban.background}}" class="img-responsive center-block">
        </div>
    </div>
</body>