0
我有一个异步调用retreived的项目列表,该列表显示在ng-repeat
的帮助下。由于该列表的div容器具有固定的高度(400px),我希望滚动条位于底部。为此,我需要scrollHeight
。但postLink
中的scrollHeight
不是最终的高度,而是最初的高度。如何获得async html attribut
例
ppChat.tpl.html
<!-- Height of "chatroom" is "400px" -->
<div class="chatroom">
<!-- Height of "messages" after all messages have been loaded is "4468px" -->
<div class="messages" ng-repeat="message in chat.messages">
<chat-message data="message"></chat-message>
</div>
</div>
ppChat.js
// [...]
compile: function(element) {
element.addClass('pp-chat');
return function(scope, element, attrs, PpChatController) {
var messagesDiv;
// My idea was to wait until the messages have been loaded...
PpChatController.messages.$loaded(function() {
// ...and then recompile the messages div container
messagesDiv = $compile(element.children()[0])(scope);
// Unfortunately this doesn't work. "messagesDiv[0].scrollHeight" still has its initial height of "400px"
});
}
}
有人能解释我错过了这里?
由于这里需要的是它
亲切,创建一个plunkr,以便其他人可以编辑/改善你的代码。 –
你从哪里得到2000px的滚动高度? – Sravan