gpt4 book ai didi

javascript - 在 angularjs 中使用 $document.querySelectorAll

转载 作者:行者123 更新时间:2023-11-30 11:50:24 25 4
gpt4 key购买 nike

因为 $documentangular.element(window.document) 的包装器,理想情况下$document.querySelectorAll() 应该可以工作,但我收到一条错误消息说它不是一个函数。有人可以解释一下吗?

最佳答案

如果你想使用$document,你应该注入(inject)它(你可以使用任何其他方式注入(inject)它):

     angular.module('someModule', [])
// instead of 'controller' use whatever it is...
.controller ('SomeName', ['$document', function($document) {
// ...
}]);

然后你可以使用查询选择器(注意[0]的使用):

$document[0].querySelectorAll(/* whatever */);

关于javascript - 在 angularjs 中使用 $document.querySelectorAll,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39641412/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com