Jonathan Smith
Jonathan Smith

Reputation: 2599

Pre-selecting a select item using AngularJS not working

I have the following objects and properties:

User - TitleID
     - FirstName
     - Surname
     - EmailAddress

Titles - CodeID
       - Description

The user's title should be preselected in a select element which also contains all the other Titles from the Titles.

Although I can get all the titles to display in the select box, I cannot get it to pre-select the correct (or indeed any) title from the select box when editing a user.

This is what I have so far:

<select ng-model="user.TitleID" ng-options="title.CodeID as title.Description for title in titles track by title.CodeID">

How do I go about getting the correct title preselected with this relational data?

Upvotes: 0

Views: 39

Answers (1)

Anthony Chu
Anthony Chu

Reputation: 37520

There's a potential bug in Angular where track by and as don't work together in ngOptions.

GitHub Issue #6564

Remove the track by and it'll work...

JsFiddle

Upvotes: 2

Related Questions