I have two separate template and in both template(rendered) i am doing $(window).scroll() but however go to one template another, the $(window).scroll() is running from both, previous as well as current template.
Code Snippets as below:
dashboard1.js
Template.dashboard1.rendered = function(){
$(window).scroll(function() {
console.log('dashboard1 scroll');
//... doing pagination and sticky element for dashboard1
});
}
Template.dashboard1.destroyed = function(){
console.log('dashboard1 destroyed');
}
dashboard2.js
Template.dashboard2.rendered = function(){
$(window).scroll(function() {
console.log('dashboard2 scroll');
//... doing pagination and sticky element for dashboard2
});
}
Template.dashboard2.destroyed = function(){
console.log('dashboard2 destroyed');
}
Console:
dashboard1 destroyed
dashboard2 scroll
dashboard1 scroll
dashboard2 scroll
dashboard1 scroll
dashboard2 scroll
But if i refresh the browser, then it is coming from current template only.
Why this is happening any idea? what is the way to fix this.