2
MEDService.users("GET", "", {"action" : "getUsers"})
  .success(function(data, status, headers, config) {
    $scope.data1 = data;

have this code, how i can set this item(get from mongo) in select on front end? data1 have fields: username, name, password. I need just username

<select ng-model="??" style="display: block" >
    <option ng-selected="??"
            ng-repeat="??"
            value="???">
      ???
    </option>
</select>
2
  • You need to complement the question with the return of JSON. Commented Dec 17, 2015 at 15:56
  • <select data-ng-mode="yourRecquiredName" data-ng-options="item.UserName as item.username for item in data1 " ></select> Commented Dec 17, 2015 at 15:58

3 Answers 3

1

Assuming that your data1 looks like

data1 = [
      {name:'Real Name1', username:'username1', password: 'secret'},
      {name:'Real Name2', username:'username2', password: 'secret'},
      {name:'Real Name3', username:'username3', password: 'secret'}
    ]

try

<select ng-model="selectedUser" ng-options="user.name for user in data1"></select>

The selected user will be stored in selectedUser, you can easily validate that by using

<h2>{{selectedUser}}</h2>

in your html.

Working example: http://plnkr.co/edit/pggWiNO0TpIlCLOlFtzW

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

Comments

0

You must create another property on your scope, like selectedValue and then use this markup :

 <select ng-model="$scope.selectedValue">
     <option ng-repeat="option in $scope.data1" value="{{option.id}}">{{option.name}}</option>
 </select>

1 Comment

If this answer solved your problem, could you mark it as answered ?
0

As I understand you have something like that:

$scope.data1 = [
   {username: 'olga', name: 'Olga K', password: 'querty'}, 
   ....
];

As the result you are going to receive username in this case it's olga value.

I see two solution you can do

First solution for string array you may prepare your date to view.

$scope.data1 = $scope.data1.map(item => item.username);

Then your html may look like that

<select ng-model="SELECTED_PROPERTY" ng-options="o as o for o in data1"></select>

Second soultion when you have object array

<select ng-model="SELECTED_PROPERTY" ng-options="o.username as o.name for o in data1"></select>

NOTE: if you never use other object properties first solution is better one cause use few RAM memory.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.