Skip to content

Instantly share code, notes, and snippets.

@amnotafraid
Created November 22, 2016 23:05
Show Gist options
  • Save amnotafraid/1230b5a74020cb968d73c6331b8cc48f to your computer and use it in GitHub Desktop.
Save amnotafraid/1230b5a74020cb968d73c6331b8cc48f to your computer and use it in GitHub Desktop.
AngularJS directive to set height of element
<div class="row">
<div class="col-xs-12">
<div id="ChartDivContracts" set-graph-height ratio=".33"></div>
</div>
</div>
'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');
}
};
}]);
@amnotafraid
Copy link
Author

I wrote this directive because I needed to set the height of a

for jChartfx

@mansres
Copy link

mansres commented Dec 29, 2017

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