We can select content of HTML element using element.select(). But onmouseup action the selected text by script will be deselected. So we have to disable onmouseup action.
Source Code       DEMO

Markup

<input (focus)="selectAllContent($event)" (mouseup)="$event.preventDefault()" value="sample value"/>

Script - app.component.ts

Observe below selectAllContent function
import { Component } from '@angular/core';
@Component({
  selector: 'my-app',
  template: `
   <h4>Focus to select text</h4>
   <input (focus)="selectAllContent($event)" (mouseup)="$event.preventDefault()" value="sample value"/><br>
  `
})
export class AppComponent {
  selectAllContent($event) {
    $event.target.select();
  }
}

0 comments:

Blogroll

Follow this blog by Email

Popular Posts