Newer
Older
Directive, ElementRef, Input, OnInit
import { Subject } from 'rxjs';
selector: '[aspectScrollToIndex]'
export class ScrollToIndexDirective implements OnInit {
@Input() selectIndex!: Subject<number>;
constructor(private elementRef: ElementRef) {}
ngOnInit(): void {
this.selectIndex.subscribe((selectedIndex: number): void => {
if (selectedIndex === this.index) {
this.elementRef.nativeElement.scrollIntoView({ behavior: 'smooth' });
}
});