Sneha
Sneha

Reputation: 131

What is the type of scroll event in angular

<div (scroll)="onScroll($event)">
onScroll(event: any) {
   const value= event.target;
  }

Here instead of type "any" ,I need to put the type of the event. Can anyone help me with this.

Upvotes: 4

Views: 7368

Answers (3)

Alireza Ahmadi
Alireza Ahmadi

Reputation: 9953

You can use Event but if you are sure your target is HTMLElement you can use it like this:

event: Event & { target: HTMLElement}

onScroll(event: Event & { target: HTMLElement}) {
   ...
}

Upvotes: 2

noamyg
noamyg

Reputation: 3104

The easiest way to find out (not using the docs) would be to print the input:

 onScroll(event: any): void {
    console.log(event);
  }

enter image description here

Upvotes: 2

Joosep Parts
Joosep Parts

Reputation: 6255

It would be Event as a type.

onScroll(event: Event) {
   const value= event.target;
  }

Fired at the Document or element when the viewport or element is scrolled, respectively. https://drafts.csswg.org/cssom-view/#event-summary

An event can be triggered by the user action e.g. clicking the mouse button or tapping keyboard, or generated by APIs to represent the progress of an asynchronous task. https://developer.mozilla.org/en-US/docs/Web/API/Event

Upvotes: 6

Related Questions