【发布时间】:2017-06-03 11:49:13
【问题描述】:
我一直致力于将一个普通的静态网站转换为一个 AngularJS 网站 - 只是为了提高我在这方面的技能。
到目前为止,我已经完成了路线并且到目前为止看起来不错。
现在在主页上,我使用 ng-repeat 指令加载了滑块图像,它也可以正常工作。但我注意到滑块本身并没有发挥其应有的功能。所以我发现我在一个单独的 js 文件上创建的 jQuery 函数根本没有加载。而且我还发现这可以通过在指令中集成插件调用来实现。
所以,我做了这个:
app.directive('featuredSlider', [function() {
return {
restrict: 'A',
link: function(scope, elem, attrs) {
$(elem).owlCarousel({
itemsCustom: [
[0, 1],
[600, 2],
[1200, 4]
],
autoPlay: 3000
});
}
};}]);
我正在使用 OwlCarousel 作为滑块,但没有使用我上面所做的触发它。
顺便说一下,我的控制器是这样的:
app.controller('HomeController', function($scope) {
$scope.featuredImages = []; }
上面的 featuredImages 数组包含滑块的图片 URL。
然后,这就是滑块所在的部分。
<div class = "featured owl-carousel owl-theme featured-slider">
<div class = "item" ng-repeat = "featured in featuredImages">
<img ng-src = "{{featured.img}}" />
</div>
</div>
谁能帮帮我?我已经尝试了几种方法,但仍然没有显示和工作。
【问题讨论】:
-
我也尝试过这样做:
$(element).owlCarousel(scope.$eval(attrs.featuredSlider));仍然没有成功的机会!
标签: javascript jquery angularjs plugins directive