当DOM Load完成时,我想测量AngularJS中DOM元素的高度。
myApp.directive('domHeight',['$timeout',function($timeout){
return{
restrict:'EA',
scope:true,
link:function(scope,element,attrs){
$(document).ready(function(){
$('.required-wrapper').load(function(){
console.log( $('.required-wrapper').height());
})
})
}
}
}])

之前触发高度
答案 0 :(得分:1)
我会尝试像这样使用$ timeout
未经测试
$('.required-wrapper').load(function(){
$timeout(function() {
//As far as I know there is no event which would notify you that the loaded DOM has rendered
//So I would use the timeout instead
console.log( $('.required-wrapper').height());
}, 100);
})
答案 1 :(得分:0)
myApp.directive('domHeight',['$timeout',function($timeout){
return{
restrict:'EA',
scope:true,
link:function(scope,element,attrs){
attrs.$observe(function(){
$timeout(function(){
$(document).ready(function(){
$('.required-wrapper').load(function(){
})
})
),true)
})
}
}
}])