Created
December 4, 2013 22:07
-
-
Save mattupstate/7796475 to your computer and use it in GitHub Desktop.
A generic window resize directive to which you can add to any element to call a function on your controller
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
angular.module('something') | |
.directive 'windowResize', ($window, $parse) -> | |
restrict: 'A' | |
link: (scope, element, attrs) -> | |
w = angular.element($window) | |
fn = $parse(attrs['windowResize']) | |
handler = (event) -> | |
scope.$apply -> | |
fn(scope, {$event:event}) | |
w.bind 'resize', handler | |
scope.$on '$destroy', -> | |
w.unbind 'resize', handler |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment