У меня есть плунжер здесь - https://plnkr.co/edit/fzNJ7FLYxWbLPoxtYpEw?p=preview
Это простое угловое приложение.
Я фиксирую высоту div, используя @ViewChild и nativeElement.offsetHeight
Возможно ли использовать этот номер в блоке стилей компонента.
В моем примере я пытался это сделать, но закомментировал.
@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;
}
}