Created
November 22, 2016 23:05
-
-
Save amnotafraid/1230b5a74020cb968d73c6331b8cc48f to your computer and use it in GitHub Desktop.
AngularJS directive to set height of 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
<div class="row"> | |
<div class="col-xs-12"> | |
<div id="ChartDivContracts" set-graph-height ratio=".33"></div> | |
</div> | |
</div> |
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
'use strict'; | |
angular.module('clientApp') | |
.directive('setGraphHeight', [ | |
function () { | |
return { | |
link: function ($scope, $element, $attributes) { | |
var width = $element[0].offsetWidth; | |
var ratio = .67; | |
var height; | |
if ($scope.$eval($attributes.ratio)) { | |
ratio = parseFloat($scope.$eval($attributes.ratio)); | |
} | |
height = width * ratio; | |
$element.css('height', height + 'px'); | |
} | |
}; | |
}]); |
Without setting tag (set-graph-height) in html, Can you set height based on div Id in angularJs?
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I wrote this directive because I needed to set the height of a