【发布时间】:2017-07-23 09:27:29
【问题描述】:
我正在尝试在 Angular 2 中实现一个自定义指令来移动任意 HTML 元素。到目前为止,一切正常,除了当我单击它并想要开始移动时,我现在不知道如何获取 HTML 元素的初始位置。我正在使用这两个主机绑定绑定到我的 HTML 元素的 top 和 left 样式:
/** current Y position of the native element. */
@HostBinding('style.top.px') public positionTop: number;
/** current X position of the native element. */
@HostBinding('style.left.px') protected positionLeft: number;
问题是他们两个开头都是undefined。我只能更新也会更新 HTML 元素但我无法读取的值?应该是这样吗?如果是的话,我有什么替代方法来检索 HTML 元素的当前位置。
【问题讨论】:
标签: html angular angular2-hostbinding