0

I have a drop down select menu and i want to store the selected value in the controller.i.e If office1 is selected then Office! is selected in the scope and so. I am unable to store the value in the controller as I am new to angularjs.Can somebody Help Heres my dropdown code

    <div class="col-xs-12">
<h5>Select the System:</h5>

   <select id="repeatSystem" ng-model="selectedSystem" style="width: 100%">
    <option ng-repeat="(key,value) in systems" value="{{key}}">{{key}}</option>
</select>

 <select id="repeatOffice" ng-model="selectedState" style="width: 100%">
    <option ng-repeat="system in systems[selectedSystem]" value="state">{{system}}</option>
</select>

</div>

here is the plunker link http://plnkr.co/edit/nNsM4VMVeHXS2hDIsAAd?p=preview

1
  • It matters when you want to get value in controller?? Commented Oct 14, 2015 at 10:10

3 Answers 3

3

Because you are binding select dropdown with ng-model then you can simply access these value in your controller.

This will give you first dropdown selected value

$scope.selectedSystem //same in view {{selectedSystem}}

This is for second

$scope.selectedState //same in view {{selectedState}}

DEMO select value and check.


Updates

I have updated this following line, where you had hardcoded value="state" to i changed it to value="{{state}}":

<option ng-repeat="state in result[selectedArea]" value="{{state}}">{{state}}</option>

See Updated DEMO

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

4 Comments

I also want to add that he should change the value="state" to value="{{state}}" or tong-value="state"
I don't understand what you want to do explain it more.
In the second select with id="repeatOffice", all options would have the value which is "state" rather than the actual value for each state. and I don't think that's what the OP wants. To get the actual value of the selected item, value="state" should be changed to value="{{state}}" or to ng-value="state"
@Dola got this point updated answer and added information. I believe this is what OP want.
1

I'm a bit confused about how to answer the question. The value of the drop-downs in the controller will be bound to the variables:

$scope.selectedArea and $scope.selectedState depending on what values are selected in the view. The value attribute that you're setting is overriding it however.

I've updated your plunkr here: http://plnkr.co/edit/F2KqqtWKvPndv7y6un1F?p=preview

I've also demonstrated setting initial values in your dropdowns that will remove that annoying "blank" option.

Comments

1

You can get the answer from this link http://forum.ionicframework.com/t/get-selected-value-from-a-select/20241

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.