2014-10-30 16 views
0

我的HTML文檔是使用title元素創建的,作爲其樣板的一部分。angular.iselement對於我知道存在的元素返回false

在我的JS我有:

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

,彈出了 '假' 跑時。爲什麼當元素明顯存在時會發生這種情況?我覺得我錯過了一些完全明顯的東西。最終,我試圖用angular.element()而不是document.getElementById或document.getElementByClass來選擇元素,但它就像DOM對於Angular是不可見的。請注意,我不能包含jQuery(不是我的決定)。在嘗試訪問DOM時,我應該堅持使用原生JS嗎?

回答

0

這是因爲angular.isElement需要一個節點元素或jQuery包裹的元素。 您可以更改您的代碼:

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

比較:AngularJS documentation on isElement

+0

謝謝!這樣可行。我無法在任何地方找到一個不成文的例子。 – 2014-10-30 15:55:33

相關問題