I have successfully implemented a solution in Angular 1.5 by creating a custom directive (see TypeScript example below).
One challenge I encountered was that there is no built-in way to select the entire value of an input with type="number". To overcome this, my strategy involved temporarily changing the input type to text while editing the value, and then reverting it back to the original type upon blur.
This approach may allow users to enter "invalid" data into the field temporarily, but once they finish editing and blur out, the browser's native number validation logic will kick in and prevent any invalid submissions. While there may be some potential pitfalls, this method works effectively in Chrome and Firefox based on our testing.
/// Selects the entire input value on mouse click.
/// Works with number and email input types.
export class SelectOnClick implements ng.IDirective {
require = 'ngModel';
restrict = 'A';
private ogType: any
constructor(private $window: ng.IWindowService) { }
link = (scope: ng.IScope, element: any) => {
element.on('click', () => {
if (!this.$window.getSelection().toString()) {
this.ogType = element[0].type;
element[0].type = 'text';
element[0].setSelectionRange(0, element[0].value.length);
}
})
element.on('blur', () => {
element[0].type = this.ogType;
})
}
static factory(): ng.IDirectiveFactory {
var directive = ($window: ng.IWindowService) => new SelectOnClick($window);
directive['$inject'] = ['$window'];
return directive;
}
}