插入符插入Angular4 + [英] Caret insert in Angular4+

查看:62
本文介绍了插入符插入Angular4 +的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在将光标插入到特定光标位置的文本区域时,我完全陷入了角项目.我尝试将标签/文本动态插入到选定光标位置的文本区域.

I am totally stuck with angular project in doing caret insert to text area at a particular cursor position. I try to insert labels/text dynamically to text area in selected cursor positions.

你能帮我吗?

谢谢,Sreepriya J

Thanks, Sreepriya J

推荐答案

如果要将光标聚焦在特定位置,则需要使用selectionStart本机元素

If you want to focus the cursor at specific position you need to use selectionStart native Element

var startPos=this.r.nativeElement.selectionStart;
this.r.nativeElement.focus();

然后您需要将先前的值与当前值连接起来

Then you need to concat the previous value with current value

this.r.nativeElement.value=this.r.nativeElement.value.substr(0,this.r.nativeElement.selectionStart)+e+this.r.nativeElement.value.substr(this.r.nativeElement.selectionStart,this.r.nativeElement.value.length);

在此处检查示例: https://stackblitz.com/edit/angular-hn8unq

这篇关于插入符插入Angular4 +的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆