Skip to content

Instantly share code, notes, and snippets.

@mattupstate
Created December 4, 2013 22:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mattupstate/7796475 to your computer and use it in GitHub Desktop.
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
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