0
I have a page in my project that contains several categories and in each category, has a Flexslider with images. Each category is displayed once and when clicking another, the previous one is hidden and the clicked one is displayed, scheme similar to Tabs.
I need that when I click on another category, it destroy the Flexslider function initialized in the previous category and run in this category.
Follow what I’ve done so far, but without success:
Function that starts Flexslider:
vm.sliderCol = function () {
setTimeout(function () {
$('.sliderCol').flexslider({
animation: "slide",
controlNav: false
});
}, 1000);
}
Function I entered in the category button:
vm.clicou = function(){
$('.sliderCol').flexslider("destroy");
console.log('destruiu');
setTimeout(function () {
vm.sliderCol();
console.log('iniciou');
}, 1000);
}
Until then, I tried to destroy the Flexslider, I do not know if there is any method to stop performing the function and start it, someone can help?
What the function
vm.sliderCol()
does? Do you know if it is working? For within the Angularjs usesetTimeout
is not the right method. The right one is to replace it with$timeout
.– celsomtrindade
Yeah, I replaced it with $timeout. The vm.sliderCol function starts the Flexslider, referring to my answer below, when I click on a category, I destroy the flex and start again with the function, because as it is as a None display in a tab, it does not take the height of the div and so it was not being displayed. But destroying the function of the flex and starting again it takes the height, because when starting the tab is already open.
– Maurício Krüger
Got it. But then, why are you wearing a
$timeout
with only 100 of delay? I know that many people use it to "activate" the changes within the middleAngular
. Would that be your case? If so, maybe it’s best to use$digest()
, would not be your case?– celsomtrindade
Good tip, I will research on and implement :D
– Maurício Krüger
Read my answer: http://answall.com/questions/139220/fun%C3%A7%C3%A3o-n%C3%A3o-executa-sem-settimeout/140117#140117 Address this question =D
– celsomtrindade