1

I have an Excel-style grid of inputs and I want to use the left right arrow keys to navigate between cells, but only when there are no characters in the input, or when the cursor is to the far left or right of the characters. So I've got:

console.log('selectionStart: ', currentCell.nativeElement.selectionStart);
console.log('selectionEnd: ', currentCell.nativeElement.selectionEnd);

where currentCell is an ElementRef. However, no matter where the cursor is with the characters, both of these always return null (if nothing is selected, both selectionStart and selectionEnd should return the same integer value; if there is a selection, these should be different values, but there should always be a value). Any ideas on why this might not be working?

4

1 回答 1

1

我只是尝试将输入类型更改为文本(它是数字),现在它可以工作了。我很好奇为什么 selectionStart 和 selectionEnd 在不使用的情况下可用于数字输入。

于 2019-03-28T17:19:43.487 回答