Я делаю приложение в Angular 6, и у меня есть следующее html:
<div #timeline class="p-timeline">
<div class="p-marker" *ngFor="let exp of experiences; let i=index"
[ngStyle]="getMarkerStyle(exp, i)">
</div>
</div>
и следующий текст:
export class TimelineComponent {
constructor() { }
@ViewChild('timeline')
public timeline: ElementRef;
public getMarkerStyle(exp: ExperienceModel, i: number): any {
if (!this.timeline || !this.timeline.nativeElement) {
return {};
}
const element = this.timeline.nativeElement as HTMLElement;
const height = element.clientHeight;
return {
top: ((height / (this.experiences.length - 1)) * i) + 'px'
};
}
Мой вопрос: Как мне перезапустить функцию getMarkerStyle, когда this.timeline.nativeElement
станет доступным? Для того, чтобы установить верхнее значение?
Я привык к Vue. js, который вроде как имеет эту встроенную функциональность.
Новичок в Angular, поэтому открыт для совета о том, как изменить существующий код.
Спасибо!