Selected combo component

Asked

Viewed 131 times

1

I have a problem loading the screen with a selected combo item. I’ve tried with jQuery, angular and it didn’t work. I’ve researched other answers around here and it didn’t work any of the alternatives. Does anyone have any idea what it might be ?

    <div class=" form-group col-md-3">
       <label class="lb">A Rendimento</label> 
         <select  ng-change="selecionaArendimento(nota.flagARendimento)" id="flagRendimento"  ng-model="nota.flagARendimento" class="form-control">
              <option  ng-selected="selected" value="0">Não</option>
              <option value="1" >Sim</option>                 
         </select>
      </div>      
  • No need to fire a change event in the combo?

  • @dvd I did not understand your questioning...

  • It seems to me that a function is called when the combo option is changed (change)... when loading the page, it is necessary to trigger the change event or nothing happens without the user changing a combo option.

  • You want the combo to be selected in the item that is in the model nota.flagARendimento, that’s it?

  • Edit your question and post the controller with javascript to make it clearer!

  • @Ricardopunctual yes!

  • I understand, I put an answer with the code example

Show 2 more comments

2 answers

1


ng-selected should be a logical expression, can be done like this:

<select  ng-change="selecionaArendimento(nota.flagARendimento)"  ng-model="nota.flagARendimento" class="form-control">
  <option ng-selected="nota.flagARendimento == '0'" value="0">Não</option>
  <option ng-selected="nota.flagARendimento == '1'" value="1">Sim</option>                 
</select>

0

You have to compare on ng-selected the value of option with what you have in nota.flagARendimento

<option ng-selected="nota.flagARendimento == 0" value="0">Não</option>
<option ng-selected="nota.flagARendimento == 1" value="1">Sim</option>

And I believe you can remove the ng-change of select, at specifics ng-model it should already update what you define in ng-model with the new value selected, in this case nota.flagARendimento.

What you should do is call the function selecionaArendimento when the nota.flagARendimento mute.

Browser other questions tagged

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