So I have this app in angular2 where I need to scroll a component horizontally but with buttons right and left. So I need a function for each button that scroll to right or
Import ViewChild and ElementRef to get elemenet refrence.
use #localvariable as shown here, get element in component, change scrollvalue, An example is shown below@ViewChild('widgetsContent', { read: ElementRef }) public widgetsContent: ElementRef
this.widgetsContent.nativeElement.scrollTo({ left: (this.widgetsContent.nativeElement.scrollLeft + 150), behavior: 'smooth' });
import { Component, OnInit, ViewChild, ElementRef } from "@angular/core";
@Component({
selector: 'my-app',
template: `