javascript - ng-options with one object -
i have callback either can array multiple objects, or 1 object:
$http.get($rootscope.appurl + '/nao/abb/getstationdata/' + selectedsupercustomer.superkund_id).success(function(data) { $scope.stationoptions = data; if($scope.stationoptions instanceof array) { //array of objects angular.foreach($scope.stationoptions, function(option) { console.log(option); if(option.nao_adsl_stationer_id === $scope.abbdata.nao_adsl_stationer_id) { $scope.selectedstation = option; } }) } else { //only 1 object if($scope.stationoptions.nao_adsl_stationer_id === $scope.abbdata.nao_adsl_stationer_id) { $scope.selectedstation = $scope.stationoptions; } } });
if array multiple objects, don't have problem loop them out ng-options, when callback 1 object, this:
{"nao_adsl_stationer_id":"33","namn":"malm\u00f6 - arl\u00f6v","stationskod":"arv","ipserie_id":"","net":"","mask":"","ip":""}
it don't work.
i use ng-options this:
<td><select class="form-control input-sm2" ng-disabled="!selectedsupercustomer" ng-model="selectedstation" ng-options="item item.namn item in stationoptions" ng-change="onchangestation(selectedstation)"><option value=''>välj station</option></select></td>
either return array 1 object in (so rid of else part of code) or construct array inside else part this
$scope.selectedoptions = [data]; $scope.selectedstation = $scope.stationoptions[0];
Comments
Post a Comment