0
我有这个指令来计算divs的高度。在编译angularJS之后是否可以加载自定义指令?
// Directive to log a height. We have to add on some value to a final height, because css style will be undefined.
rootApp.directive('logHeightCategories', ['$timeout', function($timeout) {
return {
restrict: 'A',
link: function(scope, element) {
scope.prepMaxHeightCat = element.prop('offsetHeight');
scope.value = 0;
$timeout(function() {
scope.maxHeightCat = scope.value + scope.prepMaxHeightCat;
}, 0);
}
};
}]);
的CSS规则max-height: {{maxHeightCat}}px
被应用到该div动画目的。然而,闪烁效应破坏了欲望目标。所以我已经为该div添加了ng-cloak
到display:none
。
我认为ng-cloak
被渲染为最后,因此我认为我的指令logHeightCategories
之前执行。所以我总是得到0px
的结果。
...即使我已经添加了一个$timeout
函数,希望我能克服执行时间,但我认为情况并非如此。
我申请与范围'prepMaxHeightCat'股利,因为我看到你排除了数学,但无论如何,我得到了'0px'输出。 –
我错过了那条线。添加。不需要'$ .timeout',你可以在'attrs'上放置'scope。$ watch',当它改变完成时''compile'' scope'就是想法。 –
控制台日志中还有'ele未定义'的referenceError。我已经在angularjs文件中检查了'ng-cloak'指令,它带有'priority:-10'。我现在不知道,这里的优先是否起到任何作用。 –