javascript - Generating options and selecting the first result automatically -
this i've struggled quite while now. objective populate select box variable list of greetings , have automatically select first 1 instead of being blank space.
<label>check me select: <input type="checkbox" ng-model="selected"> </label><br/> <select> id="greetings"> <option ng-repeat="greeting in myctrl.greetinglist" ng-selected="selected">{{ greeting }}</option> </select> the ng-selected directive (and indeed selected attribute, simpler solution) indeed select item list on form load, defaults last item on list. capture first element in list , generate rest, can't think there's more elegant solution out there. ideas?
by way, know ng-options better ng-repeat. problem need each of options have ng-click directive. can't achieve ng-options.
you should try $first plus assign model select. in way
<select data-ng-model="greetings"> <option data-ng-repeat="greeting in myctrl.greetinglist" data-ng-selected="$first" data-ng-value={{greeting.id}}>{{ greeting }}</option> </select> there special properties too. of them below
$index
$first
$middle
$last
$even
$odd
Comments
Post a Comment