-1

I set the default value in a dropdown, but i see always the first option selected, but if i click the dropdown the value that i want is set.

CONTROLLER

tantoSvagoApp.controller("ricercaAttivita", function ($scope, $http) {
  $scope.selectedRegione = regione;
});

HTML

<select class="trip dark" ng-model="selectedRegione" ng-options="regione.nome as regione.nome for regione in regioni.regionSelector">
  <option value="">TUTTE</option>
</select>
2
  • What is regione? You haven't defined it anywhere. What is regioni? You haven't defined it anywhere. Commented Jul 3, 2017 at 15:45
  • Check the answer. I have assumed a similar data array as per your HTML to demonstrate you how the things work. Commented Jul 3, 2017 at 15:54

1 Answer 1

0

You can have a look at this code

<div ng-app="myapp">
    <fieldset ng-controller="FirstCtrl">
        <select  ng-options="regione.nome as regione.nome for regione in regioni.regionSelector"
           ng-model="selectedRegione"></select>

        {{ selectedRegione }}
    </fieldset>
</div>

Controller

var myapp = angular.module('myapp', []);
myapp.controller('FirstCtrl', function ($scope) {
  $scope.selectedRegione = 'Mike';
    $scope.regioni = {
    'regionSelector':[
        { id: 1, nome: 'John'},
        { id: 2, nome: 'Rocky'},
        { id: 3, nome: 'Mike'},
        { id: 4, nome: 'Ben' }
    ]
    };
});

The <option> is created dynamically and the value for the dropdown is pre-selected by $scope.selectedRegione = 'Mike'; which reference the nome: 'Mike' of the $scope.regioni.regionSelector array.

For simplicity and work around here is the link to JSFIDDLE

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.