I have a simple select element that I am trying to enforce a value being present to submit the form and I have tried both setting the required attribute as well as using ng-init to ensure there is a value selected and both fail.
I am using ng-options
to create a list of values from an array of Objects that have a ref property. Then I would like to use ng-init
to set the shown value to the first Object.ref in the array.
<select name="refmarker" class="input-block-level form-width-adjust" ng-model="model.refmarker" ng-options="rm.ref for rm in refmarkers" ng-disabled="editable" ng-init="model.refmarker='refmarkers[0].ref'" required></select>
I have tried the following without any luck
ng-init="model.refmarker='refmarkers[0]'"
ng-init="model.refmarker='refmarkers[0].ref'"
ng-init="model.refmarker='rm.ref'"
Also the required
attribute doesn't work ? Is the angular select element buggy or am I doing something wrong?
required will only work in side a form element.
What you want is ng-init="model.refmarker=refmarkers[0]"