2016-05-01 70 views

回答

0

這裏是例子:

angular.module(‘app’) 
      .directive('calculateHeight', calculateHeight); 

     function calculateHeight($window) { 
      return function (scope, element) { 
       var w = angular.element($window); 
       scope.getWindowDimensions = function() { 
        return { 'h': $window.outerHeight, 'w': $window.outerWidth }; 
       }; 
       scope.$watch(scope.getWindowDimensions, function (newValue, oldValue) { 
        scope.windowHeight = newValue.h; 
        scope.windowWidth = newValue.w; 
        var matches = document.querySelectorAll(「div.panelBody」); // use selector to the element 
        matches[0].style.height = yourCustomHeight; 
       }, true); 

       w.bind('resize', function() { 
        scope.$apply(); 
       }); 
      }; 
     }