AngularJS - bind to directive resize

后端 未结 6 1834
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:12

    A slight variation on Eliel's answer worked for me. In the directive.js:

          $scope.onResizeFunction = function() {
          };
    
          // Call to the function when the page is first loaded
          $scope.onResizeFunction();
    
          angular.element($(window)).bind('resize', function() {
            $scope.onResizeFunction();
            $scope.$apply();
          });
    

    I call

        $(window).resize();
    

    from within my app.js. The directive's d3 chart now resizes to fill the container.

提交回复
热议问题