简体   繁体   中英

angular 6 scroll top not working in mat angular

public expenseClicked(cat_id: any, label: any,e) {
window.scrollTo(0, 0);
console.log(e);
//this.expense_chart_data('YES', cat_id, label);
if (this.clickbtn_status === 1) {
    this.backbtn_status = 'A';
    this.click_count = this.click_count + 1;
    // this.chartLevel = this.chartLevel + 1;
    //console.log('chartClicked inside ====' + cat_id);
    this.expense_chart_data('YES', cat_id, label);
}
this.expense_chart_data('YES', cat_id, label);

}

{{chartlist.name}} {{chartlist.value | currency:'INR'}} arrow_forward_ios

Use ViewportScroller

Inject ViewportScroller in constructor and It provide method called scrollToPosition

Try this

component.html

constructor(private viewportScroller: ViewportScroller) {} 

component.ts

public expenseClicked(cat_id: any, label: any,e) {
this.viewportScroller.scrollToPosition([0, 0]);
console.log(e);
//this.expense_chart_data('YES', cat_id, label);
if (this.clickbtn_status === 1) {
    this.backbtn_status = 'A';
    this.click_count = this.click_count + 1;
    // this.chartLevel = this.chartLevel + 1;
    //console.log('chartClicked inside ====' + cat_id);
    this.expense_chart_data('YES', cat_id, label);
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM