Guest User

Untitled

a guest
Apr 20th, 2018
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.59 KB | None | 0 0
  1. import { Directive, ElementRef, HostListener } from '@angular/core';
  2.  
  3. @Directive({
  4. selector: 'ion-searchbar[select-all],ion-input[select-all]'
  5. })
  6. export class SelectAll {
  7.  
  8. constructor(private el: ElementRef) {
  9. }
  10.  
  11. @HostListener('ionFocus')
  12. selectAll() {
  13. // access to the native input element
  14. let nativeEl: HTMLInputElement = this.el.nativeElement.querySelector('input');
  15.  
  16. if (nativeEl) {
  17. if (nativeEl.setSelectionRange) {
  18. // select the text from start to end
  19. return nativeEl.setSelectionRange(0, nativeEl.value.length);
  20. }
  21.  
  22. nativeEl.select();
  23. }
  24. }
  25. }
Add Comment
Please, Sign In to add comment