(function() { 'use strict'; angular.module('shared') .directive('windowSize', ['$window', function ($window) { return { restrict: 'A', link: function(scope, element, attrs) { scope.windowWidth = $window.innerWidth; function onResize() { if (scope.windowWidth !== $window.innerWidth) { scope.windowWidth = $window.innerWidth; scope.$digest(); } } function cleanUp() { angular.element($window).off('resize', onResize); } angular.element($window).on('resize', onResize); scope.$on('$destroy', cleanUp); } }; }]); })();