ng-options "selected" does not work

2

I'm using the ng-options function and it's listing correctly, it just is not showing the value marked as default: selected

Code:

<select class="form-control" 
   ng-model="genericCustomersViewModel.customer.addresses[0].stateId"
   ng-options="state.id as state.initials for state in 
   genericCustomersViewModel.allStates track by state.id" 
   ng-change="genericCustomersViewModel.getCityByState(0)" 
   ng-selected="genericCustomersViewModel.customer.addresses[0].stateId">
</select>

AllStates

[{  "id":1,
    "description":"ACRE",
    "initials":"AC",
    "specificCountryCode":12,
    "countryId":30 },
{   "id":2,
    "description":"ALAGOAS",
    "initials":"AL",
    "specificCountryCode":27,
    "countryId":30 },
{   "id":3,
    "description":"AMAPÁ",
    "initials":"AP",
    "specificCountryCode":16,
    "countryId":30}]

Customer

{  "rg":null,
   "inscricaoMunicipal":null,
   "inscricaoEstadual":null,
   "cpfCnpj":"13",
   "inscricaoEstadualIndicator":null,
   "phoneNumber2":null,
   "phoneNumber3":null,
   "emailNfe":null,
   "emailBoleto":null,
   "branchesIds":[],
   "id":12,
   "name":"Razão social",
   "companyName":null,
   "mainPhoneNumber":null,
   "mainEmail":null,
   "site":null,
   "entityType":1,
   "isActive":true,
   "isDeleted":false,
   "contacts":[],
   "addresses":[  
      {  "id":1,
         "description":null,
         "addressType":0,
         "postalCode":93700,
         "address1":"Balduino Dreger",
         "address2":"Não tem",
         "number":345,
         "district":"Bela Vista",
         "cityId":null,
         "stateId":20,
         "countryId":null,
         "entityId":12
      },
      {  "id":2,
         "description":"Comercial",
         "addressType":0,
         "postalCode":93700,
         "address1":"Rua dos bobos",
         "address2":"Num tem",
         "number":666,
         "district":"Centro",
         "cityId":4057,
         "stateId":19,
         "countryId":null,
         "entityId":12
      }
   ]
}
    
asked by anonymous 21.06.2016 / 14:38

1 answer

1

I was able to solve this problem by passing the whole object, instead of passing only the state ID (stateId). In ng-model it is necessary to pass all the selected object, for example:

{   "id":2,
    "description":"ALAGOAS",
    "initials":"AL",
    "specificCountryCode":27,
    "countryId":30 
}  

Instead of passing only the value 2.

    
21.06.2016 / 19:16