I have 100 controllers and I need binda scrollevent for one of them.
When the controller starts, the scroll event listener attaches to the document and works correctly. but when the controller changes, the scroll event remains and causes a problem in another controller!
The only solution I find is that the unbindevent is scrollin all the other 99 controllers, but this is stupid!
angular.module('test', ['ngRoute'])
.config(function($routeProvider){
$routeProvider
.when('/c1', {controller:'c1', templateUrl:'/c1.html'})
.when('/c2', {controller:'c2', templateUrl:'/c2.html'})
...
.when('/c100', {controller:'c100', templateUrl:'/c100.html'})
.otherwise({redirectTo: '/c1'});
})
.controller('c1', function($document){
...
$document.bind('scroll', function(){...});
...
})
.controller('c2', function($document){
$document.unbind('scroll');
...
})
...
.controller('c100', function($document){
$document.unbind('scroll');
...
})
What is the right way?
source
share