I have an input element and it has text inside it by using ng-model, then I'm trying to select all text by creating custom 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();
});
}
};
})
It works well, but I don't want it's text to be also selected when user foucusout from the control and focusin again. It should just select text only once (not on second focus).
Also how can I remove focus from element when all text is selected?