我在使用Javascript的角度2中。如何获得角度为2且只有javascript的指令中的当前元素的访问权限
在一个指令中,我需要访问当前元素才能操作DOM。
请注意,我不能在hashtag(#element
)中使用这个技巧,因为我会有很多像这样的元素。每个人都会有我的指示。
的Html
<p [focus]="p1.focus"></p>
<p [focus]="p2.focus"></p>
<!-- ... -->
的Javascript
(function (app) {
app.Focus =
ng.core.Directive({
selector: "[focus]",
inputs: ['focus'],
}).Class({
constructor: function() {
// how get access to the current element here
}
})
})(window.app || (window.app = {}));
你知不知道我该怎么办呢?
不幸的是,正式文件还没有为JavaScript
你试过用'this'吗? – vinagreti
'this'返回指令,但不返回DOM中的当前元素。 –
我可以告诉你打字稿吗?你能转换它吗? – micronyks