This is easily done with jQuery:
var msgs = $(".messages ul")
var scroll = false
if( msgs[0].scrollHeight === (msgs.scrollTop() + msgs.outerHeight() ) )
{
scroll = true
}
$scope.messages.push(data)
if(scroll)
{
setTimeout(function(){
msgs.scrollTop(msgs[0].scrollHeight) // Allow it to update!
},0)
}
To give some context, ul is the container of the messages, I iterate over the array in $scope.messages and if the container is scrolled to the bottom it will stick to the bottom.
This implementation works for me.
Now, I recently learned how one shouldn't really use jQuery in angular. But I am wondering, how would I achieve something like this in pure AngularJS?