简体   繁体   English

将插入符/光标移动到文本区域/输入中的最终位置— Ionic 3,Angular2 +

[英]Move caret/cursor to the end position in textarea/input — Ionic 3, Angular2+

When I use the method below the cursor doesn't move to the end (actually it appears at the beginning) of the textarea... So I can't edit it... How could I solve that? 当我使用下面的方法时,光标不会移到文本区域的末尾(实际上它显示在文本区域的开头)。所以我无法对其进行编辑。我该如何解决呢?

HTML HTML

 <button ion-button (click)="addText('hello')">
    Text
  </button>

 <ion-textarea [(ngModel)]="model">
 </ion-textarea>    

TS TS

addText(text) {
    this.model = this.model + text;
  }

You can use the setFocus method of the DOM element ion-textarea queried by a ViewChild : 您可以使用ViewChild查询的DOM元素ion-textareasetFocus方法:

HTML HTML

<button ion-button (click)="addText('hello')" #modelTextarea>
  Text
</button>

<ion-textarea [(ngModel)]="model">
</ion-textarea>    

TS TS

@ViewChild('modelTextarea') modelTextarea;
model: string;

addText(text) {
 this.model = this.model + text;
 this.modelTextarea.setFocus();
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Angular 2 contenteditable div,将插入符号移到最终位置 - Angular 2 contenteditable div, move caret to end position Angular - 如何在 textarea 中设置插入符号 position - Angular - How to set caret position in textarea Ionic [Angular] - 反应形式:使用 setValue() selectionStart/End 后不会移动 cursor - Ionic [Angular] - Reactive form: after using setValue() selectionStart/End doesn't move cursor Ionic 4: ion-textarea setfocus 未设置 cursor 最后 position 的文本 - Ionic 4: ion-textarea setfocus not set cursor at last position of text Angular2+ 自动对焦输入元素 - Angular2+ autofocus input element Ionic:当点击输入或textarea时,iOS文本光标不显示 - Ionic: iOS text cursor not showing up when tapped input or textarea 在 Angular 中的 TextArea 内的当前(或最后)插入符号位置插入文本; 元素不被解释为 TextArea - inserting text in current (or last) caret position inside of TextArea, in Angular; Element is not interpreted as TextArea 使用带有Angular2 +的VMWare Clarity Design隐藏可扩展Datagrid上的插入符号列 - Hide the caret column on expandable Datagrid with VMWare Clarity Design with Angular2+ Json Input Ionic 3和Angular 6的意外结束 - Unexpected end of Json Input Ionic 3 & Angular 6 在 Angular2+ 中设置日期的输入格式 - Set input format of date in Angular2+
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM