Angular2 keyup event update ngModel cursor position jumps to end
You need to wrap following lines in setTimeout() call. The reason is that you need to give browser time to render new value and only then change cursor position which gets reset after new value rendering. Unfortunately, this will cause a little flickering, but I wasn't able to find any other way to make it work.
setTimeout(() => {
this.el.nativeElement.selectionStart = pos;
this.el.nativeElement.selectionEnd = pos;
});
You can change position of a cursor without setTimout() and flickering as suggested in accepted answer with setSelectionRange() like this:
this.el.nativeElement.setSelectionRange(position, position, 'none');
Example: stackblitz