2
In an input I have a method that selects the content of the field when clicking on it.
<input ng-click="selecionaTudo($event)">
That’s the job of:
$scope.selecionaTudo= function($event){
$event.target.select();
}
It works perfectly, but I want to use it in ng-Focus, and in that event it doesn’t work:
<input ng-focus="selecionaTudo($event)">
Can anyone tell me why? What alternatives do I have?
Call the function it normally calls. in both cases. But the . select() function does not work in ng-Focus, only in ng-click. what I want is when I enter the field(receive Focus), the content of the field is all selected, to facilitate editing. so I don’t need to click on the field to select the value, I can use tab, enter for example. o . value didn’t work for me.
– Geferson
i tested it here in an app of mine. From a console.log($Event.target) within its function, see what’s coming.
– André Vicente
$Event.target returns the element in both events, I have now tested, the strange thing is that . select() works on ng-click and does not work on ng-Focus, nor . value.
– Geferson
I tested it here on Chrome and it worked with . value, weird. If you change the way to call the function also gives, put an ng-model="fieldName" and send in the call of the function ng-Focus="selectTudo(fieldName)", if it doesn’t work out shows how your form is to see if there is something missing, here in my test the . Right value on any input on android and Chrome.
– André Vicente
I think I expressed myself wrong, the "select everything", is not recovering the value of the field in js, but I want you to select all the content of the field in the view. I added in the post the result of how I would like it to stay.
– Geferson
now I get it. I was really trying to pass you the value. I’ll see here if I can get what you’re looking for.
– André Vicente