1

I'm trying to make a menu where I can change the "cell" property of a person. Cells are defined as:

Cells: [
{ name: 'NE', id: 1 },
{ name: 'NW', id: 2 },
{ name: 'SE', id: 3 },
{ name: 'SW', id: 4 }
]

My html code

<div><select ng-model="ui.returnedPeopleList[row.rowIndex]" ng-options="cell for cell in Cells"></select></div>

returnedPeopleList is an array of people. Basically what I have is a grid of people. Double clicking a person opens a modal instance where you can change their properties (hence, the row.rowIndex). The row is passed to the instance modal instance, where the changes are made. I'm not sure how much of this is relevant to the dropdown; I'm pretty new to angular.

The dropdown menu is empty, and I have no idea what's wrong. Thanks in advance.

4
  • Cells: ... should be Cells = .... You aren't setting the variable. Commented Aug 13, 2014 at 19:23
  • Reproduce the problem in jsfiddle and post jsfiddle link. Commented Aug 13, 2014 at 19:27
  • Some Fiddle: jsfiddle.net/fess81/9Ymvt/2044 Commented Aug 13, 2014 at 19:30
  • Casey: I believe Cells: ... is correct. Cells = ... makes visual studio mad. Unfortunately, I'm unable to navigate to jsfiddle at work. If you need another relevant piece of code, just ask :) Commented Aug 13, 2014 at 19:38

3 Answers 3

1

You need the right syntax for ng-options

ng-options="cell.id as cell.name for cell in Cells"

Will produce the following option elements:

<option value="1">NE</option>
<option value="2">NW</option>
<option value="3">SE</option>
<option value="4">SW</option>
Sign up to request clarification or add additional context in comments.

2 Comments

I see how my original code was wrong, but the menu is still empty even after I made this fix ):
Is Cells defined correctly, @david? See my comment up top.
1

One problem is that you in your ng-options. Your display value is going to be the object in the list, not the object property you want.

Try:

ng-options="cell as cell.name for cell in Cells"

Also make sure Cells is on your $scope.

Comments

1

Below code may help you <div><select ng-model="returnedPeople" ng-options="cell as cell.name for cell in Cells" ng-change="ui.addToPeopleList(returnedPeople)"></select></div>.I think ng-model is not setting the value to ui.returnedPeopleList[row.rowIndex].

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.