[英]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-textarea
的setFocus
方法:
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.