我的内容使用 ng-cloak 指令,我想在指令中使用 innerHeight() 获取元素高度。
但是,当使用 innerHeight() 时,该元素被 ng-cloak 隐藏,因此结果始终为 0。
我试过了
link: function postLink(scope, element, attrs) {}
或者
$timeout(function(){}
但同样的结果。
有人知道这个功能或事件吗?
谢谢。
我的内容使用 ng-cloak 指令,我想在指令中使用 innerHeight() 获取元素高度。
但是,当使用 innerHeight() 时,该元素被 ng-cloak 隐藏,因此结果始终为 0。
我试过了
link: function postLink(scope, element, attrs) {}
或者
$timeout(function(){}
但同样的结果。
有人知道这个功能或事件吗?
谢谢。
这个解决方案对我有用:
使用 ng-cloak 在你体内的 div 中添加“data-ng-init”函数调用。
<body layout="row" ng-cloak>
<div ng-controller="PageCtrl" data-ng-init="onloadFunction()">
...
在您的 app.controller 中,定义此函数并将您的代码添加到“else”子句中:
$scope.onloadFunction = function() {
if (angular.element(document.body)[0].className == 'ng-cloak') {
$timeout(function() {
$scope.onloadFunction();
},100);
} else {
// Here, page is displayed.
}
}
希望这可以帮助。