D
D
Drovosek012021-06-25 13:28:54
Angular
Drovosek01, 2021-06-25 13:28:54

What does the prefix document: mean when listening to events and where can I read about it?

In Angular, I faced the task of tracking keystrokes in a component and executing certain logic when certain keys are pressed.

For example, so that when you press the left or right arrows on the keyboard, the displayed photos scroll in the corresponding directions.

The problem is that if I just listen for 'keyup' or 'keydown' (or 'keyup.ArrowLeft' and 'keyup.ArrowRight'), then the logic doesn't work.
If I first add the text "document:" to the above key events, then everything works fine as intended.
There are examples here - https://stackoverflow.com/questions/42348837/angul...

Actually, I want to know where I can see the documentation on what kind of prefixes there are in general, in addition to "document:" and why the handler does not work without them?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Shohruh Shaimardonov, 2021-06-25
@joeberetta

The problem is that if I just listen for 'keyup' or 'keydown' (or 'keyup.ArrowLeft' and 'keyup.ArrowRight'), then the logic doesn't work.

That's right, because keypress events are bound to the entire document, not to any specific home node.
The prefix 'document:' actually means that this method will listen to global events, not to events on a specific element
Another question was asked here, but the answer explains what it is and how it works
Ps the question is more related to Angular, add a tag to the question

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question