0

I'm getting a JSON value from one WebService like this

"electricity":

{ "selectedElectricityBoard":"ABCD",

"electrictyConsumerNumber":"12345",

"isElectricityBoardChecked":true

}

I generated a Drop Down list from the JSON data,after that i select the value and submit the value, the value gets submitted successfully from my UI, now the case is I'm editing the same form for which i'm making a Web Service call which returns me the same value, which i have selected from the UI, but the selected value is not being populated/reflected in the drop-down menu, any suggestion or help would be highly appreciable, My UI is in Angular JS, the code snippet is as follows :

      <div class="col-xs-2 no-padding ">
      <label>Consumer No.:</label>
      </div>
      <div class="col-xs-3">
       <span ng-hide="true" class="form-control" ng-required="true"
        close-text="Close">
       </span>
     <div class="group-3-text-boxes col-xs-3 no-padding" style="min-width: 100px;">
     <input type="text" name="consumer_number"
 ng-disabled="!form_data[selectedTab].electricity.isElectricityBoardChecked"
 ng-model="form_data[selectedTab].electricity.electrictyConsumerNumber"
 class="input-field"
ng-class="{true:'invalid-field',false:''}
 form_data[selectedTab].electricity.isElectricityBoardChecked &&   form_data[selectedTab].invalid.electricity]" required />
1
  • where is drop-down in your code ? Commented Feb 10, 2017 at 18:44

1 Answer 1

1
<html ng-app="app" ng-controller="ctrl">
<select id="state" ng-model="states" ng-options="state for (state,states) in total_states">
    <option value=''>Select State</option>
</select>
<select id="district" ng-model="districts" ng-options="district for (district,districts) in states">
    <option value=''>Select District</option>
</select>
<select id="city" ng-model="cities" ng-options="cities for cities in districts">
    <option value=''>Select City</option>
</select>
<br>
<br>
<br>

State ::  {{states}}
<br>
<br>
<br>
District:: {{districts}}
<br>
<br>
<br>
City ::  {{cities}}

for controller:

app.controller('ctrl',ctrl);
ctrl.$inject=['$scope'];
function ctrl($scope) {
    $scope.total_states = {
        'Andhra Pradesh': {
            'Prakasam': ['Ongole', 'Chirala', 'Mrakapuram'],
            'Krishna': ['Vijayawada', 'Machalipatnam'],
            'Guntur': ['Guntur', 'Tenali', 'Bapatla']
        },
        'Telangana': {
            'Hyderabad': ['Hyderabad'],
            'Warangal': ['Wrangal', 'Hanmkonda'],
            'Khammam': ['Khmammam', 'Badrachalam']
        }
    };

}

try this it works...

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

1 Comment

its didn't worked, here i'm attaching your plunker only, you will get to know that your code is not working plnkr.co/edit/cAO5s9kubHN4VJgdUnHu?p=preview

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.