src/dynamic-height.directive.ts
selector | [dynamicHeight] |
Properties |
|
Methods |
Inputs |
HostListeners |
constructor(el: ElementRef)
|
||||||||
Defined in src/dynamic-height.directive.ts:19
|
||||||||
Parameters :
|
bottomBar
|
Type: |
Defined in src/dynamic-height.directive.ts:16
|
isFullScreen
|
Type: |
Defined in src/dynamic-height.directive.ts:14
|
topBar
|
Type: |
Defined in src/dynamic-height.directive.ts:15
|
window:resize |
Arguments : '$event'
|
window:resize(event: any)
|
Defined in src/dynamic-height.directive.ts:40
|
getBordersWidthByElement | ||||||||
getBordersWidthByElement(el: )
|
||||||||
Defined in src/dynamic-height.directive.ts:56
|
||||||||
Parameters :
Returns :
{ borderTop: any; borderBottom: any; }
|
ngOnInit |
ngOnInit()
|
Defined in src/dynamic-height.directive.ts:23
|
Returns :
void
|
setFullScreenHeight |
setFullScreenHeight()
|
Defined in src/dynamic-height.directive.ts:48
|
Returns :
void
|
setParentHeight |
setParentHeight()
|
Defined in src/dynamic-height.directive.ts:52
|
Returns :
void
|
Private _componentSectionsHeight |
_componentSectionsHeight:
|
Type : number
|
Defined in src/dynamic-height.directive.ts:19
|
Private _parentContainerHeight |
_parentContainerHeight:
|
Type : number
|
Defined in src/dynamic-height.directive.ts:18
|
import {
Directive,
ElementRef,
HostListener,
Input,
OnInit
} from '@angular/core';
@Directive({
selector: '[dynamicHeight]'
})
export class DynamicHeightDirective implements OnInit {
@Input() isFullScreen: boolean;
@Input() topBar: HTMLElement;
@Input() bottomBar: HTMLElement;
private _parentContainerHeight: number;
private _componentSectionsHeight: number;
constructor(private el: ElementRef) { }
ngOnInit(): void {
const topBarBorders = this.getBordersWidthByElement(this.topBar);
const topBarHeight = this.topBar.offsetHeight + topBarBorders.borderBottom + topBarBorders.borderTop;
const bottomBarBorders = this.getBordersWidthByElement(this.bottomBar);
const bottomBarHeight = this.bottomBar.offsetHeight + bottomBarBorders.borderBottom + topBarBorders.borderTop;
this._componentSectionsHeight = (topBarHeight + bottomBarHeight);
if (this.isFullScreen) {
this.setFullScreenHeight();
} else {
this._parentContainerHeight = this.el.nativeElement.parentNode.parentNode.parentNode.height;
this.setParentHeight();
}
}
@HostListener('window:resize', ['$event']) onWindowResize(event: any) {
if (this.isFullScreen) {
this.setFullScreenHeight();
} else {
this.setParentHeight();
}
}
setFullScreenHeight() {
this.el.nativeElement.style.height = (window.innerHeight - this._componentSectionsHeight).toString() + 'px';
}
setParentHeight() {
this.el.nativeElement.style.height = (this._parentContainerHeight - this._componentSectionsHeight).toString() + 'px';
}
getBordersWidthByElement(el) {
return {
borderTop: parseFloat(getComputedStyle(this.topBar).borderTop.split(' ').join('')),
borderBottom: parseFloat(getComputedStyle(this.topBar).borderBottom.split(' ').join(''))
}
}
}