I have a directive that determines the size and width of some elements, but when I change the size of the page it does not adapt. I would like a way that when the user changes the dimensions of their browser the angular call back to directive.
I have a directive that determines the size and width of some elements, but when I change the size of the page it does not adapt. I would like a way that when the user changes the dimensions of their browser the angular call back to directive.
You can use $ watch, as in this example:
app.directive('myDirective', ['$window', function ($window) {
return {
link: link,
restrict: 'E',
template: '<div>window size: {{width}}px</div>'
};
function link(scope, element, attrs){
scope.width = $window.innerWidth;
angular.element($window).bind('resize', function(){
scope.width = $window.innerWidth;
// manuall $digest required as resize event
// is outside of angular
scope.$digest();
});
}
}]);
Example quoted link