I hope you guys are doing very good in your life. I am trying to make a select box with a default selection and allowing user to change the selection if they want.
Here is the JSFiddle: https://jsfiddle.net/ibnyusrat/jf5gggj0/
I am using this line to write the select box and its options:
<select name="defaultQuality" ng-model="CreatePlayer.form.defaultQuality" ng-options="item.quality as item.label for item in CreatePlayer.getQualities() track by item.quality">
<option style="display:none" value="">Select a quality</option>
</select>
And the function that produces the options is:
CreatePlayer.getQualities = function(){
var c = Array();
c[0] = {quality:"SD",label:"SD"};
if(CreatePlayer.form.p1080){
c[1]={quality:"HD",label:"HD"}
}
return c;
}
If I remove this line:
CreatePlayer.form.defaultQuality = {quality:"SD",label:"SD"};
It does seem to work. The issue is, if I don't define a default option, the select works as it should. But the moment I define a default option, and then I programmatically add an option to the list, changing selection causes the select box to revert to the empty value for the firs time, but in all the following times it works. So the user actually has to select the option twice to get it to recognize it.
Am I making a very obvious mistake here? Please help.
track by item.qualityand you should be fine