I have an input element and it contains the text inside it using ng-model, then I try to select all the text by creating my own detective:
.directive('selectText', function() { return { require: 'ngModel', link: function(scope, elem, attrs, ctrl) { elem.bind('focus', function() { $(elem).select(); }); scope.$watch("edit",function(newValue,oldValue) { $(elem).select(); }); } }; })
This works well, but I do not want the text to be also selected when the user foucusout from the control and focusin again. It should just select the text only once (not in the second focus). Also, how can I remove focus from an element when all the text is selected?
source share