1
的高度,我有以下DOM:訪問編譯的transcluded範圍來計算元素
<carousel calculate-carousel-height>
<slide ng-repeat="article in bestArticles" active="slide.active">
<div>{{article.text}}</div>
</slide>
</carousel>
的carousel
指令使用transcluded範圍,所以我可以在我的自定義指令calculate-carousel-height
的鏈接功能得到它:
link: function (scope, element, attributes, ctrl, transcludeFn) {
transcludeFn(function(clonedTranscludedContent) {
// here I can access the transcluded scope
});
}
但是,問題是這個範圍還沒有編譯(ng-repeat指令還沒有被處理),所以我沒有article.text
並且不能計算包含文本的DOM的高度。如何以及何時可以在編譯完成後訪問transcluded作用域?
這將工作,但它是最好的解決方案?
link: function (scope, element, attributes, ctrl, transcludeFn) {
setTimeout(function() {
// angular finished its magic and I can access compiled transcluded DOM here
}, 0);
}