Created
October 25, 2014 17:04
-
-
Save codeshrew/2edbb4163fac7f9aba03 to your computer and use it in GitHub Desktop.
Angular select directive with initial selection and track by
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- This is an example for initiating the selection in a dropdown to a saved setting | |
In this case, we're using mongo to store a collection of programs and another to store a collection of projects | |
The projects reference the ObjectId of a program at `project.program` --> | |
<select | |
ng-init="selectedProgram.program = { _id: project.program }" | |
ng-change="project.program = selectedProgram.program._id" | |
ng-model="selectedProgram.program" | |
ng-options="program.name for program in programs track by program._id"> | |
<!-- To have a default selection if there is no match to a program _id, just set an option with an empty value --> | |
<option value="">– Select a program –</option> | |
</select> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I made a handy little AngularJS directive for handling dropdowns in a sane way: https://github.com/codeshrew/angular-sane-dropdown