2017-03-02 7 views
1

メッセージを含むメッセージコンテナブロックがあります。スクロールをこのdivの下に移動するにはどうすればよいですか?私はそれを底に移動する指示を持っていますが、それは適切に機能しません。div要素の最後にスクロールバーを移動するanglejs chat

テンプレート:

<div class="message-area scroll default always-visible" scroll-bottom="$ctrl.allMessages"> 
     <div class="container-column-fluid"> 
      <message-container ng-repeat="message in $ctrl.allMessages" message="message"></message-container> 
     </div> 
    </div> 

が指令:

function scrollBottom() { 
    return { 
     scope: { 
      scrollBottom: "<" 
     }, 
     restrict: 'A', 
     link: function(scope, element, attr) { 
      scope.$watchCollection('scrollBottom', function(newVal) { 
       if (newVal) { 
        $timeout(function() { 
         element[0].scrollTop = element[0].scrollHeight; 
        }, 0); 
       } 

      }); 
     } 
    }; 
} 

export { scrollBottom }; 

答えて

1

ああ、私はすべての日が働いて...関数内で$タイムアウトを挿入するために忘れてしまった...

function scrollBottom($timeout) { 
    return { 
     scope: { 
      scrollBottom: "<" 
     }, 
     restrict: 'A', 
     link: function(scope, element, attr) { 
      scope.$watchCollection('scrollBottom', function(newVal) { 
       if (newVal) { 
        $timeout(function() { 
         element[0].scrollTop = element[0].scrollHeight; 
        }, 0); 
       } 

      }); 
     } 
    }; 
} 

export { scrollBottom }; 
+0

デフォルト値に$ timeoutの2番目の引数(遅延)は0です。したがって省略することができます。 –

関連する問題