AngularJS - bind to directive resize

后端 未结 6 1831
Happy的楠姐
Happy的楠姐 2020-12-08 20:18

How can i be notified when a directive is resized? i have tried

element[0].onresize = function() {
            console.log(element[0].offsetWidth + \" \" +          


        
6条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-08 21:06

    Here a sample code of what you need to do:

    APP.directive('nvLayout', function ($window) {
      return {
        template: "
    ", restrict: 'EA', link: function postLink(scope, element, attrs) { scope.onResizeFunction = function() { scope.windowHeight = $window.innerHeight; scope.windowWidth = $window.innerWidth; console.log(scope.windowHeight+"-"+scope.windowWidth) }; // Call to the function when the page is first loaded scope.onResizeFunction(); angular.element($window).bind('resize', function() { scope.onResizeFunction(); scope.$apply(); }); } }; });

提交回复
热议问题