angular.iselement为我知道的元素返回false

时间:2014-10-30 14:24:03

标签: javascript angularjs

我的HTML文档是使用title元素作为其样板文件的一部分创建的。

在我的JS中我得到了:

console.log("angular.isElement('title'): ", angular.isElement('title'));

哪个突然出现' false'什么时候跑。当元素明显存在时,为什么会发生这种情况?我觉得我错过了一些完全明显的东西。最终我尝试使用angular.element()而不是document.getElementById或document.getElementByClass来选择元素,但它类似于DOM对Angular是不可见的。请注意,我不能包含jQuery(不是我的决定)。我是否应该在尝试访问DOM时坚持使用本机JS?

1 个答案:

答案 0 :(得分:0)

这是因为angular.isElement需要一个节点元素或一个jQuery包装元素。 您可以将代码更改为:

console.log("angular.isElement('title'): ", angular.isElement(document.querySelector('title')));

比较:AngularJS documentation on isElement