Select a default setting that does not work with Ionic Framework

I am using the Ionic Framework.
I would like to introduce the first option as the default, but doing it this way does not work.
What can I do?

<select ng-model="newSpesaAereo.valuta"> <option ng-selected="selected">Euro</option> <option>Dollaro</option> <option>Dollaro canadese</option> <option>Sterlina</option> </select> 

enter image description here

If I analyze the page using the Google Chrome Developer Utility, I will watch this.

enter image description here

If I edit this HTML code and I delete the selected line, then the euro will appear.

Why is this happening?

+6
source share
3 answers

You need to use ng-selected instead of the selected one.

https://docs.angularjs.org/api/ng/directive/ngSelected

 <select ng-model="newSpesaAereo.metodoPagamento"> <option ng-selected="selected">Carta di credito</option> <option>Bancomat</option> <option>Contanti</option> <option>Altro</option> </select> 
+2
source

Set ng-selected="true" .

Example:

 <option ng-selected="true">Carta di credito</option> 
+13
source

The reason the default option doesn't work is because in your controller, you probably initialized your form model as follows:

 $scope.newSpesaAereo = {} 

If you want to set the default form parameters, you must also set them in the form model. For example, set 'valuta' to 'Euro' as follows:

  $scope.newSpesaAereo = { valuta: "Euro" } 

Hope this helps!

PS When posting such questions, you must also include the controller code that the view is associated with.

+10
source

Source: https://habr.com/ru/post/974974/


All Articles