Say that I bind an array to a select
tag using the following:
<select ng-model="selData" ng-options="$index as d.name for d in data">
In this case, the associated option
tags are assigned a sequence of index values: (0, 1, 2, ...). However, when I select something from the drop-down, the value of selData
is getting bound to undefined
. Should the binding actually work?
On the other hand, say that I instead do the following:
<select ng-model="selData" ng-options="d as d.name for d in data">
Here, the option
tags get the same index, but the entire object is bound on change. Is it working this way by design, or this behavior simply a nice bug or side-effect of AngularJS?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…