I would like to 'data bind' the default value of a html/jade select. Here is my select:
select#title.form-control(ng-model='newClient.title')
option(ng-repeat='title in titles', ng-selected='$first') {{title}}
The problem here is that if I don't touch the select, my newClient.title will be set as undefined and not the first title value. How can I do that without setting a default value in my controller?
You want to use ng-options to define the options, and then simply specify the ng-model for the first element. You don't have to worry about an ng-init.
<select ng-options="title for title in titles" ng-model='titles[0]'></select>
For reference, there's some pretty good documentation here.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With