I have a plunker here - https://plnkr.co/edit/fzNJ7FLYxWbLPoxtYpEw?p=preview
Its a simple angular app.
I'm capturing the height of a div using @ViewChild and nativeElement.offsetHeight
Is it possible to uss this number in the styles block of the component.
In my example I have attempted it but commmented it out.
@Component({
selector: 'my-app',
templateUrl: './src/app.html',
styles: [`
.blockTwo {
background: yellow;
//height: this.contentHeight+px;
height: 200px;
}
`]
})
=
import {Component, ElementRef, ViewChild, AfterViewInit} from '@angular/core';
@Component({
selector: 'my-app',
templateUrl: './src/app.html',
styles: [`
.blockTwo {
background: yellow;
//height: this.contentHeight+px;
height: 200px;
}
`]
})
export class AppComponent implements AfterViewInit{
@ViewChild('content')
elementView: ElementRef;
contentHeight: number;
constructor() {
}
ngAfterViewInit() {
this.contentHeight = this.elementView.nativeElement.offsetHeight;
}
}
[style.height.px]="contentHeight"
. – ConnorsFan