I've got a Mongoose schema which uses enumeration on one of its fields such as below.
var testSchema = new Schema({
name: {
type: String,
default: '0',
enum: ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '11', '12', '13', '14'],
trim: true,
required: 'Title cannot be blank'
}
});
I would like to display the enums as options in a view with this code, but I'm unable to accomplish.
<datalist id="enums" data-ng-repeat="x in test.name.enumValues" >
<option data-ng-bind="x"></option>
</datalist>
Is there any possible way that I can do to display these enumerations in the view? Thanks in advance.
I had a similar problem. Check out the answer to this question. It should be what you are looking for.
Angular JS ng-options with simple array init
gist:
in your controller you can have something like:
$scope.enumOptions = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '11', '12', '13', '14'];
In your view:
<select ng-model="yourModel" ng-options="o as o for o in enumOptions"></select>
I hope that helps.