Select list option selected with Angularjs

Asked

Viewed 2,727 times

4

I’m implementing a select list that has as options the Brazilian states.

I would like to return the selected value according to the return of a web service. For example, if the service returns RJ then RJ must be the option Selected.

This is very simple to implement with Javascript and Jquery, but I’ve never done it in Angular. Someone has a suggestion?

 <select id="txtUf" class="customSel">
    <option value="0" selected="selected">Selecione</option>
    <option value="AC">AC</option>
    <option value="AL">AL</option>
    <option value="AP">AP</option>
    <option value="AM">AM</option> 
    ...
 </select> 

1 answer

6


<select id="txtUf" class="customSel" ng-model="Dados.uf">
    <option value="0" selected="selected">Selecione</option>
    <option value="AC">AC</option>
    <option value="AL">AL</option>
    <option value="AP">AP</option>
    <option value="AM">AM</option> ...  
</select> 

The solution would be to include the ng-model, "Uf" is the value of the state symbol, remembering that the value of Data.Uf must be equal to the value of the option value.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.