Here is a snippet. Q2 is selected as I expect.
<select name="quarter" ng-model="Quarter" > <option value="1" >Q1</option> <option value="2" ng-selected="Quarter=='Q1'">Q2</option> <option value="3">Q3</option> <option value="4">4</option> </select>
Changing 'Q1'
to 'Q2
' makes nothing as selected as I expect. Now putting ng-selected="Quarter=='Q1'"
DOES NOT make Q1 selected until i delete ng-selected="Quarter=='Q2"
wtf. How is this suppose to work?
Definition and Usage. The ng-options directive fills a <select> element with <options>. The ng-options directive uses an array to fill the dropdown list. In many cases it would be easier to use the ng-repeat directive, but you have more flexibility when using the ng-options directive.
The ngInit directive allows you to evaluate an expression in the current scope. This directive can be abused to add unnecessary amounts of logic into your templates. There are only a few appropriate uses of ngInit : aliasing special properties of ngRepeat , as seen in the demo below.
In AngularJS when you are using ng-options, you can filter out the options by calling a custom function you have in the controller. Let's say you have following set of employees and when you display all these employees inside HTML select using ng-options, you can see all the employees in a dropdown.
If you put the ng-selected on the option element, your option will be selected when the ng-selected value is true. In your case, the option Q2 is selected when Quarter is equal to Q1.
If you want to select the value passed in Quarter, you must put the ng-selected on the select element :
<select name="quarter" ng-model="Quarter" ng-selected="Quarter" ng-options="Quarter for Quarter in Quarters" > {{Quarter}} </select>
Take a look at the select directive documentation.
<select ng-model="hour"> <option ng-selected="hour == $index" ng-repeat="h in (((b=[]).length=24)&&b) track by $index" ng-bind="$index">{{h}}</option> </select>
if you want a select for 24 hour, you can do this.
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