0

how can I get the value of selected drop down (1,2 or 3)? my js as below

$scope.priority = [
    {
     "level":"Urgent",
     "index":1
    },

    {
     "level":"Very Important",
     "index":2
    },

    {
     "level":"Important",
     "index":3
    }
];

html

<select class="btn btn-priority" ng-options="p.level for p in priority">
   <option value="">priority</option>
</select>

2 Answers 2

1
<select ng-model="selectedPriority" class="btn btn-priority" ng-options="p.level for p in priority">
   <option value="">priority</option>
</select>

You can use ng-model attribute to get it.

$scope.selectedPriority

Here is the JsFiddle

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

2 Comments

I got an object. I tried ng-model="selectedPriority.index" to try to get the index but it returned undefined?
See I have added the jsFiddle link.
0

Besides using ng-model you should use the select as label for value in array syntax to specify the value of options:

<select ng-model="selectedPriority" ng-options="p.index as p.level for p in 
 priority">
   <option value="">priority</option>
</select>

Fiddle

This allows you to get rid of ng-change overhead. Read more in the docs.

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.