scrollable icon indicating copy to clipboard operation
scrollable copied to clipboard

Scroll doesn't work with ngFor

Open doidd opened this issue 8 years ago • 3 comments

I following demo and simple edit code like this <ul> <li *ngFor="let num of [1,2,3,4,5,6,7,8,9,10]" [class.current]="id == 's'+ num " (click)="scrollTo('#s'+num, '#v-scrollable')">{{num}} </ul>

scrolled to: {{id}} <div id="v-scrollable" class="scrollable section" ng2-scrollable (elementVisible)="id = $event.id"> <div *ngFor="let num of [1,2,3,4,5,6,7,8,9,10]" [id]="'s'+ num "> Section {{num}} (scroll to here) </div> </div> but demo don't work. How can i fix that?

doidd avatar May 29 '17 09:05 doidd

It works for me. https://plnkr.co/edit/6eyLtM?p=preview&open=app.component.ts

allenhwkim avatar Aug 21 '17 20:08 allenhwkim

It works because you don't use a ngfor.. :

app.tpl.html

<legend>Scroll Within Window</legend>
<div class="scrollable" 
  (elementVisible)="wid = $event.id"
  (elementHidden)="whid = $event.id"
  ng2-scrollable>
  **<div id="w1">One</div>
  <div id="w2">Two</div>
  <div id="w3">Three</div>
  <div id="w4">Four</div>
  <div id="w5">Five</div>
  <div id="w6">Six</div>
  <div id="w7">Seven</div>
  <div id="w8">Eight</div>
  <div id="w9">Nine</div>**
</div>
<div style="height: 1600px"> Spacing </div>

Christophe-re avatar Aug 22 '17 09:08 Christophe-re

I am not sure people really do repeat *ngFor for sections. We may need setTimeout() to solve this within ngAfterViewInit https://github.com/ng2-ui/scrollable/blob/master/src/scrollable.directive.ts#L40

allenhwkim avatar Aug 22 '17 15:08 allenhwkim