When I try to load options with an arrangement that has the format I leave you, the first option is blank and the following are the values of my arrangement. That's a problem for me when I try to select one other option I can not get the value.
<select ng-model='form.type'
ng-options="item.name for item in organizations"
ng-change="update({{form.type.id}})">
</select>
Format :
{"status":0,"Area":[{"id":"1","name":"Marketing","private":null},{"id":"2","name":"Ventas","private":null},{"id":"5","name":"Soporte","private":null}],"Count":3}
Controller :
$scope.organizations = data.Area;
What's happening in your case is that your ng-model
variable, which is form.type
, does not contain a value of your options in the select dropdown list. That's why you see an empty row. If you want it to be, for instance, the first one, you can do this (I changed to selected
variable, but it doesn't matter at all):
$scope.organizations = [{"id":"1","name":"Marketing","private":null},{"id":"2","name":"Ventas","private":null},{"id":"5","name":"Soporte","private":null}];
$scope.selected = $scope.organizations[0].id;
Now, the selected
variable has the id
of your option. But that's not all. You also need to modify your HTML a bit, to have the ng-options
have the id
as your value. It can be anything you want in the object, not necessarily the id
, but that's why I assumed you needed, you can change it:
<select ng-model='selected' ng-options="item.id as item.name for item in organizations" ng-change="update({{selected}})">
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.