2017-09-04 51 views
0

我需要知道,如果一个元素id="Tags"是目前我角的控制文件中....Angular的jQueryLite如何通过id查找元素?

所以我做检查(即时窗口调试结果):

?angular.element($document).find("#Tags").length 
0 
?$("#Tags").length 
1 
?angular.element($document.querySelector('#Tags')) 
VM1119:1 Uncaught TypeError: $document.querySelector is not a function 

只是想知道,如何让jQueryLite通过ID查找元素...

+0

随着AngularJS框架,一个通常使用的[属性指令(HTTPS://docs.angularjs .org/guide/directive)。该元素在postLink函数中作为'element [0]'或者指令控制器在'$ element [0]'中可用。 – georgeawg

回答

3

你不能。但是你可以使用JavaScript的香草

var el = document.getElementById("Tags"); 

而且你可以把结果变成jqLit​​e选择

angular.element(el);