ng-model does not take the value of a Select - AngularJs

0

I have the following html:

<label class="item item-input item-stacked-label" ng-repeat="nl in normativas">
    <select ng-model="nl.idResultado">
        <option value="1">CUMPLE</option>
        <option value="2">NO CUMPLE</option>
        <option value="3"> NO APLICA </option> 
    </select>
</label>
<button ng-click="guardarNormativas()"> Guardar</button>

This html is used so that the user can select an option of the select, that value (1, 2, 3) is stored inside "nl.idResultado". and when the button is pressed the data of this object is saved in a db sqlite.

Everything is kept perfect, "n1.idResult" takes the value 1,2,3 depending on the user's choice.

The problem occurs when editing, I USE THE SAME html to show the select with the selected option (which was previously saved).

"nl.idResultado" let's say that it contains 1 (check that I get it from the DB), but the select is empty, it should be generated with the option selected by default "CUMPLE".

Why does this happen? ... What am I doing wrong?

    
asked by ELM 24.05.2018 в 16:24
source

2 answers

0

The value of a <select> is always a string.

Did you try to parse the values of% co_from% to string?

    
answered by 24.05.2018 в 18:08
0

Is your Normative object where the values are that fill your list?

If so, angular has ng-options for these cases, and so "automatic" performs the set of your ng-model, I'll give you an example:

link

I hope I can help, greetings!

    
answered by 07.09.2018 в 22:40