最佳答案
我得到了一个看似简单的问题,却没有明显的 (通过阅读 Angular JS 文档)解决方案。
我有一个 Angular JS 指令,它基于其他 DOM 元素的高度进行一些计算,以定义 DOM 中容器的高度。
类似的情况也在指令内部发生:
return function(scope, element, attrs) {
$('.main').height( $('.site-header').height() - $('.site-footer').height() );
}
The issue is that when the directive runs, $('site-header')
cannot be found, returning an empty array instead of the jQuery wrapped DOM element I need.
Is there a callback that I can use within my directive that only runs after the DOM has been loaded and I can access other DOM elements via the normal jQuery selector style queries?