2017-11-15 3 views
1

ここではドキュメントはあまり役に立ちません。私はアプリケーションで完璧なスクロールバーを使用して、すべてのブラウザとの互換性の問題を回避したいと考えています。ここに記載されているとおりにコードを正確に初期化しましたhttps://github.com/zefoy/ngx-perfect-scrollbar/tree/4.x.x/。 これは私が、私は、コンテナが最新のメッセージに自動スクロールする各新しいメッセージのために、今の私のhtml角度4の完全スクロールバーで自動スクロールを有効にする方法は?

<perfect-scrollbar id="chat" [config]="config"> <li *ngFor="let message of messages"> {{messages}} <li> </perfect-scrollbar>

に何をしたかです。さらにドキュメンテーションを読むと、イベントを呼び出す指示があることがわかりました。これは先にリンクした文書の終わりに記載されています。だから、私のアプローチは、同じコンポーネントで、次のされています

import {PerfectScrollbarComponent } from 'ngx-perfect-scrollbar'; 
... 

constructor(private scrollbar:PerfectScrollbarComponent) { } 
... 

    ngDoCheck() { 
    var chat = document.getElementById('chat'); 
    this.scrollbar.directiveRef.scrollToBottom(chat.scrollHeight); 
    } 

PerfectScrollbarComponentがプロバイダであることを期待していますので、これは私にエラーを与えます。私がそれをした後、私は別のエラーを取得します。ElementRefのプロバイダがありません!

私はこれ以上の睡眠を失っています。誰もが角度4のperfectscrollbarで自動スクロールを実装する方法の提案を提案できますか? は、次のように私もこれに多くの時間を過ごし、この問題を解決し

答えて

0

事前にありがとう:

HTML:

<perfect-scrollbar class="window__list"> 
    ... 
</perfect-scrollbar> 

コンポーネント:

... 
import { PerfectScrollbarComponent } from 'ngx-perfect-scrollbar'; 

export class ChatWindowComponent implements OnInit { 
    ... 
    // Linking to component that using perfect-scrollbar 
    @ViewChild(PerfectScrollbarComponent) public directiveScroll: PerfectScrollbarComponent; 
    ... 
    constructor() { } 
    ... 
    toBottom(): void { 
    if (isUndefined(this.directiveScroll)) return; 
    this.directiveScroll.directiveRef.scrollToBottom(0, 100) 
    } 
} 
関連する問題