Created
          January 7, 2016 08:06 
        
      - 
      
- 
        Save KillerCodeMonkey/832af4de84c08fccf909 to your computer and use it in GitHub Desktop. 
    Angular directive to get size of an element
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | angular.module('app', ['ionic']).directive('elementSize', [ | |
| '$timeout', | |
| function ($timeout) { | |
| return { | |
| restrict: 'A', | |
| link: function (scope, element, attrs) { | |
| element.ready(function () { | |
| var height, | |
| width; | |
| $timeout(function () { | |
| height = element[0].offsetHeight; | |
| width = element[0].offsetWidth; | |
| if (attrs.key) { | |
| scope[attrs.key] = { | |
| height: height, | |
| width: width | |
| }; | |
| return; | |
| } | |
| scope.elementSize = { | |
| height: height, | |
| width: width | |
| }; | |
| }); | |
| }); | |
| } | |
| }; | |
| } | |
| ]); | |
| // usage e.g. <ion-content element-size key="contentSize"> | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment