我正在尝试在 ng-include 中获取我的按钮的引用!但这不起作用。 (我在 index.html 中加载 script.js)。
我的 script.js 中的代码:
buttons = Array.prototype.slice.call( document.querySelectorAll( '#st-trigger-effects > button' ))
我的 ng-include Controller 中的代码:
<div id="st-trigger-effects" class="column">
<button data-effect="st-effect-3" class="pushmenutest">Push</button>
</div>
供您引用,当我将“div”代码直接放入index.html 时,它可以工作!我不知道为什么,当我将代码放入 ng-include View 中时它不起作用。当然可以,因为“DOM”尚未加载? 我尝试在文件末尾插入 script.js 。但我得到了同样的结果。
我正在尝试使用这个库:http://tympanus.net/Development/SidebarTransitions/
最佳答案
如果该线是单独存在的并且不在 Angular 上下文中。它将在 ng-include 完成之前运行。因此 querySelector 将找不到该元素。
我猜是这种情况,因为你说如果直接将其包含在 .html 中,它就可以工作。
是否有原因导致您需要像这样按住按钮而不能使用 ng-click
?
如果您向我们提供更多信息,我们可以为您提供进一步帮助。
关于javascript - Angularjs:在 ng-include 中获取 document.querySelectorAll,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30162537/