This directive can help to relate the height between the elements, the demo version is
https://plnkr.co/edit/hpIlWxP2DbtGgVGdrcbk?p=preview
app.directive('bindTo', function($document, $window) {
return {
restrict: 'A',
link: function(scope, element, attr) {
if(!attr.bindTo) {
console.log('bindTo element not defined');
return;
}
var windowElm = angular.element($window),
bindToElm = angular.element($document[0].querySelector(attr.bindTo));
if(!bindToElm) {
console.log('defined bindTo element ', attr.bindTo, ' not found');
return;
}
windowElm.on('resize', bindHeight);
scope.on('someEvent', bindHeight);
bindHeight();
function bindHeight() {
var bindToElmHt = bindToElm.height();
element.css('height', bindToElmHt);
}
}
};
});
Use will be such
<div class="common">
Common
</div>
<div class="user-panel" bind-to=".common">
User Panel
</div>
source
share