看到你让我走上正确的道路来解决我遇到的问题,下面是我的指令和 html
angular.module('portal.directives', [])
.directive('bootCarousel', function(){
return function(scope, elem, attrs) {
scope.carouselPrev = function(){
$('#'+attrs.id).carousel('prev');
}
scope.carouselNext = function(){
$('#'+attrs.id).carousel('next');
}
}
});
html:
<div id="carousel-generic" class="carousel slide" data-slide="cycle" boot-carousel>
<!-- Indicators -->
<ol class="carousel-indicators">
<li data-target="#carousel-generic" data-slide-to="{{$index}}" ng-class="{'active': $index == 0, '': $index != 0}" ng-repeat="banner in banners"></li>
</ol>
<!-- Wrapper for slides -->
<div class="carousel-inner">
<div ng-class="{'item active': $index == 0, 'item': $index != 0}" style="height: 340px; background: #c33" ng-repeat="banner in banners">
<div ng-bind-html-unsafe="banner.sContent"></div>
<div class="carousel-caption">
</div>
</div>
</div>
<!-- Controls -->
<a class="left carousel-control" ng-click="carouselPrev()" href="" data-slide="prev">
<img src="images/Portal_header_arrowL.png" alt="Previous">
</a>
<a class="right carousel-control" ng-click="carouselNext()" href="" data-slide="next">
<img src="images/Portal_header_arrowR.png" alt="Next">
</a>