2
我有一个指令,它把对应于其父right
CSS属性Angular2看着父母的CSS属性
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"
}
}
这只是正常的像素数。但是,如果我调整了窗口大小,我的父母也正在更改以及它的right
值。我的指令在一分钟内不适应该值。我怎么能在Angular2中看到this.el.parentNode.getBoundingClientRect().right
的值?
感谢