Created
April 12, 2018 14:16
-
-
Save tperrelli/fd17c2fe95c8b17b460b15e80687f9f6 to your computer and use it in GitHub Desktop.
Revisions
-
tperrelli created this gist
Apr 12, 2018 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,25 @@ 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('ionFocus') 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(); } } }