AngularJS - Call directive when reshaping page

0

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.

    
asked by anonymous 14.02.2017 / 22:29

1 answer

0

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

    
15.02.2017 / 17:24