I have a directive to apply some classes on elements based on the window size:
angular.module( 'myApp' ).directive('resizer', ['$window', function ($window) {
return {
link: function (scope, elem, attrs) {
angular.element($window).on('load resize', function () {
scope.$apply(function(){
scope.isSmall = $window.innerWidth < 800 ? true : false;
});
});
angular.element($window).on('$stateChangeStart', function () {
scope.$apply(function(){
scope.isSmall = $window.innerWidth < 800 ? true : false;
});
});
}
};
}]);
basically it sets: isSmall to true or false based off the window width. then my ng-click uses this value to apply my classes like so:
<div resizer ng-class="{ 'class1 class2 class': isSmall }"></div>
it works all fine and dandy but I have noticed that if the state is changed in my app to navigate back to the page with this directive applied the styles are not applied to the element. anyone know how I would solve this? I am under the impression I am adding the wrong event handlers; I tried adding a $stateChangeStart to the .on call but so far have not been able to get it working