简体   繁体   中英

How to make Angular 7 scroll to component repeated with ngFor

I have a looping template I need to scroll to specific item when that item get's active how do i do that.

My template loop is :


<div class="tabs-list-item-container"> <!-- this is a horizontal scrollable wrapper -->
   <app-tab-list-item *ngFor="let tab of tabs" [tabSession]="tab" [class.active]="tab.isActive"></app-tab-list-item>
</div>

The tab object has isActive property which I need to use and scroll to that component can it be achieved?

Whenever the user selects an item, the below method should get invoked. scrollIntoView() will scroll to the element which has .active class

scrollToActive() {
   document.querySelector('.active').scrollIntoView();
}

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