One of my directives dynamically adds the number of pixels corresponding to its parent element's right
CSS attribute.
import { Directive, ElementRef, AfterViewInit } from "angular2/core"
@Directive({
selector: "[d]"
})
export class PositioningFromParent implements AfterViewInit {
private el:HTMLElement
constructor(el: ElementRef) {
this.el = el.nativeElement
}
ngAfterViewInit() {
let v = this.el.parentNode.getBoundingClientRect().right
this.el.style[left] = v + "px"
}
}
Although it functions properly, I have noticed that when I resize the window, the parent element changes along with its right
value. My directive does not automatically adjust to reflect this change. How can I watch and update the
this.el.parentNode.getBoundingClientRect().right
value in Angular2?
Appreciate any guidance on this matter.