0

I am using AngularJS and I got a simple select element with static options. I want to get an element on a certain index of an array when i click on one option.
Forgive me if this is ridiculous but I am new with Angular JS

Here are the class and the dropdown-list

 $scope.products=[
            {
                "Id":1,
                "Name":"ice cream",
                "Price":8.50
            },
            {
                "Id":2,
                "Name":"salad",
                "Price":8.99
            },
            {
                "Id":3,
                "Name":"fish & chips",
                "Price":10.91
            }
        ]
<select name="singleSelect" ng-model="data.selectedOption">
            <option ng-repeat="product in products" ng-model="selectedOption" value="{{product.Id}}">{{product.Name}}</option>
</select>

For example when I click on ice cream, next to the dropdown-list, there should be the price of the item.

1
  • there is no ng-model on <option> . Only the <select> itself gets bound to data model Commented Jan 19, 2016 at 19:48

1 Answer 1

5

Use ngOptions on your select - put an ngModel on the select - and then simply display!

<select name="singleSelect" ng-model="data.selectedOption" ng-options="product as product.Name for product in products">
</select>

<span>Price: {{data.selectedOption.Price}}</span>
Sign up to request clarification or add additional context in comments.

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.