ng-selected not working in select element

前端 未结 4 1093
太阳男子
太阳男子 2020-11-28 15:18

I have a bound select

 tag. Take a closer look at its doc and the example.

Because the select directive's determination of the selected option is based on ngModel. Therefore, once you remove ng-selected="c.CollegeName == collegeSelection.CollegeName", your code should work.

I created a very simple plunk to demonstrate the "selected" feature in select directive.

More details:

AngularJS uses ngModel directive to enable "two-way data binding" between your model and UI elements.

In the case of "select", the model collegeSelection you specified as

That's it! The first college in the colleges array will be selected if you run the code.

Just remember collegeSelection is the selected option, no matter it's because user selected an item on the UI, or you selected an item in javascript.

That's how two-way data binding works.

提交回复
热议问题