gpt4 book ai didi

javascript - 使用带 Angular jQuery Light slider ?

转载 作者:塔克拉玛干 更新时间:2023-11-02 21:42:06 26 4
gpt4 key购买 nike

我遗漏了一些不允许我将 ng-click 添加到 slider 项的东西。当我添加 ng-click 时,它不会触发点击事件,但如果我添加 onClick,它就会触发。现在这让我觉得它与 Angular 范围有关,但我可以告诉。

编辑:

这是一些代码:

     JS

angular.module('sweetItemsDirective',[]).directive('sweetItemsDirective',
['$interval', '$q',
function($interval, $q) {
return {
restrict: 'EA',
transclude: true,
scope: {
items : '&',
},
templateUrl: '/templates/items/default.html',
controller: ['$scope', function($scope) {
// some controller code goes here
$scope.items = function(){
return $scope.items;
}

}], //Embed a custom controller in the directive
link: domManipulation
}
function domManipulation(scope, element, attrs) {

scope.items = // returned json from API;
function createSlider(){
try{
scope.itemsSlider.destroy();
}catch (error){
console.log(error);
}
scope.itemsSlider = $('#items').lightSlider({
item : 10,
autoWidth: false,
slideMove: 1, // slidemove will be 1 if loop is true
slideMargin: 1,
vertical:true,
verticalHeight:180,
adaptiveHeight:false,
keyPress: true,
controls: false,
pager: false
});
}

}
}]
);

templates/items/default.html

html

    <sweet-items-directive id="items"></sweet-items-directive>
<div ng-if="items.length > 0">
<button class="button prev">prev</button>
<ul class="available-items">
<li ng-repeat="item in items" ng-click="flavor= item.flavor">
{{ item.name }}
</li>
</ul>
<button class="button next">next</button>
</div>

最佳答案

<ul class="available-items">
<li ng-repeat="item in items" ng-click="$parent.flavor = 'item.flavor'">
{{ item.name }}
</li>
</ul>

关于javascript - 使用带 Angular jQuery Light slider ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34780439/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com