2016-09-29 4 views
0

사용자가 윈도우 높이를 변경할 때마다 요소의 위치를 ​​계산해야합니다. 지시어를 만듭니다. ?사용자가 창 높이를 변경할 때 각도로 이벤트를 트리거하는 방법?

'use strict'; 
    angular.module "myApp" 
    .directive 'uibPosition',['$position','$document','$timeout', ($position,$document,$timeout)-> 
    return { 
     restrict: 'EAC', 
     link: (scope, element, attr) -> 
//I want to Trigger this event when user change windows height 
     $timeout -> 
      if $document.height() - $position.position(element).top < 500 
      element[0].querySelector('.custom-popup-wrapper').style.top = 'auto' 
      element[0].querySelector('.custom-popup-wrapper').style.bottom = 40 + 'px' 
      else 
      element[0].querySelector('.custom-popup-wrapper').style.top = $position.position(element).top+40+'px' 
    } 
    ] 

그것을 수행하는 방법 나는 정말

답변

1

당신은 지시에 감시자를 추가 할 수 있습니다 감사 :

 var w = angular.element($window); 

     scope.getWindowDimensions = function() { 
      return { 
       "h": w.height(), 
       "w": w.width() 
      }; 
     }; 
     var watcherTimeout; 
     scope.$watch(scope.getWindowDimensions, function (newValue) { 
      $timeout.cancel(watcherTimeout); 
      watcherTimeout = $timeout(function(){ 
       scope.callback(); // call callback function 
      }, 300); 
     }, true); 

     w.bind("resize", function() { 
      scope.$apply(); 
     }); 
+0

은'WindowSizeService' 무엇인가? –

+0

불필요한 부분이었습니다. 죄송합니다 :) – olysachok

+0

그것이 보인다 works.thanks –