Just thought I would give my input (for what it is worth), I achieved this by hooking up to the click
event. In fact, I went as far as creating a directive for it:
import { Directive, ElementRef, HostListener } from '@angular/core';
@Directive({
selector: 'ion-searchbar[select-all],ion-input[select-all]'
})
export class SelectAll {
constructor(private el: ElementRef) {
}
@HostListener('click')
selectAll() {
// access to the native input element
let nativeEl: HTMLInputElement = this.el.nativeElement.querySelector('input');
if (nativeEl) {
if (nativeEl.setSelectionRange) {
// select the text from start to end
return nativeEl.setSelectionRange(0, nativeEl.value.length);
}
nativeEl.select();
}
}
}
Then you can use it as follows:
<ion-input select-all></ion-input>
Which should highlight the text upon focusing. I read a post somewhere that implied it should be on click
not focus
- I cannot recall why, but I will try to find it.