0
我有一个这样的嵌套指令。angularjs子指令元素选择
<main>
<app-header></app-header>
<app-footer></app-footer>
</main>
而且app-footer
指令有一个小div
含量约50像素的高度。
<div class="footer"></div
所以我想在main
指令链接函数中获得页脚高度。
angular.module("app").directive("main", [function() {
return {
"restrict": "E",
"transclude": true,
"template": "<h1>hello</h1><div ng-transclude></div>",
"link": link
};
function link(scope, element) {
var footerHeight1 = $(".footer").height() || 0; // returns 0
var footerHeight2 = element.find('.footer'); // returns prevObject
}
}]);
所以我不能得到页脚的高度。
**为什么**你想要的高度? **当你想要身高吗?页脚可能是动态填充的,并且在链接功能被触发时尚未填充 – devqon
请向我们显示template.html – jbrown
模板内容很简单。我更新了模板内容。 – barteloma