我不完全确定gridnav
应该如何工作,所以我不确定这是否完全有效,但是gridnav
在数组更改时调用呢?您可以通过视图将数组传递给指令,然后通过$watch
指令内的范围内的值。
HTML:
<div class="well clearfix giftCardList tj_container" id="giftCardContainer"
gridnav="giftCards">
...
JS:
link: function ($scope, element, attrs) {
// watch for the value passed in to gridnav attribute to change
$scope.$watch(attrs.gridnav, function(value){
// don't do anything unless there's actually a value
if (!value) return;
// once it's changed, call gridnav on the next loop
$timeout(function() {
$(element).gridnav({
rows: 1,
navL: '#giftCard_prev',
navR: '#giftCard_next',
type: {
mode: 'disperse',
speed: 400,
easing: '',
factor: '',
reverse: ''
}
}, 0);
}, true);
});
}
Plunker:http ://plnkr.co/edit/lMYvIJEkEPRAaNIAuNvF?p=preview