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