0

I have an array

$scope.items= [
{ name: "Name1", email: "email1", password: "pas1" },
{ name: "Name2", email: "email2", password: "pas2" }
];

I want to display email value in a select tag. I am using following code but its not working. I want first item as 'Select' :

<select id="idItem">
<option value="-1" selected="selected">Select</option>
<option ng-repeat="o.email as o.email for o in items" value="{{o.email}}"> {{o.email}}
</option>
</select>

Also user can select multiple items. When user selects multiple emails from select box, message box should popup displaying Name and password of selected users.

1
  • o.email for o in items this could be your ng-repeat. And you don't need to add extra option tag for showing select, you can use a placeholder Commented Jun 23, 2016 at 13:27

2 Answers 2

2
<select id="idItem" >
<option value="-1" selected="selected">Select</option>
<option ng-repeat="item in items" value="{{item.email}}"> {{item.email}}
</option>
</select>

I think this would work....if it doesn't plz provide your plunkr url next time

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

1 Comment

How should I display the details when I select any values from list box? note that user can select multiple values.
1

I would prefer to use ng-options if you already have a json object containing all items. Further you need to use multiple="true" for multi-select and a ng-model to store the selected results

<select id="idItem" multiple="true" ng-model="selectedItems"
        ng-options="item.email for item in items">
</select>

Then you can create a messageBox which displays the selectedItems if you want

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.