Consider I have 100 controllers and I need to bind a scroll event to one of them.
When the controller fired, the scroll event listener attached to document and work correctly. but when the controller change, the scroll event remain & cause problem in other controller!
The only solution I find is that unbind the scroll event in all of other 99 controllers but it 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?
directiveis the right way but i am beginner in angular and i am not prfessional in directive :D