Hi,
I have a service that already binds to $window's Resize event, and I expose
the Window's Height through the service
I have multiple directives that need to do stuff when the window is
resized, and I currently $watch(servc.winHeight) to do what I need
I was wondering if this approach was actually better in term of
performance, versus binding the resize event of the windows multiple times.
basically it boils down to this:
1- (simplified code)
angular.service('winStats', function($window) {
var resizeHandler = function() {
this.size = { height: $win.height()}
}
angular.element($window).bind('resize', resizeHandler);
});
Then from controllers or directives inject 'winStats', and watching like so
(assume I need to do this in 3-5 different places/directives that serves
different purposes):
$scope.$on(function() { return winStats.height;}, function(height) { [...]
});
----------------
2- from any directives I need the window's height, simply bind a new
handler in them:
angular.element($window).bind('resize', resizeHandler);
---------------
3- Or maybe leverage $rootScope.$broadcast from the Service (in option1)
and doing $scope.$on from the directives?
Thanks for your inputs
--
You received this message because you are subscribed to the Google Groups
"AngularJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.