Hey Tishi,
shouldn't be that hard to get your code working. Have a look at the docs at
https://docs.angularjs.org/api/ng/directive/select[
^]:
- Instead of options, I'd recommend using Angular's ng-options. Otherwise you have to take care yourself, that the options are created bevor an initial value is selected.
- The select element binds the selected value to ng-model. Further annotations in the options are not needed.
A possible HMTL sample could look like this:
<select name="userType" id="userType" class="form-control" ng-model="SelectedType"
required ng-options="type.Name for type in UserTypes">
</select>
<p>
Selected Instance: {{SelectedType}}
</p>
The selected object is bound to
$scope.SelectedType
$scope.SelectedType = $scope.UserTypes[2];
If you just need the selected user type, you could work with
$scope.SelectedType
. Otherwise you could implement an
ng-change function (see the
docs again) and e.g. set the selected property.
In general, I'd ask, whether it is good design to have a selected property inside the UserType data. But this goes beyond what you described above.
Hope this helps. If you have further questions, let me know.
– K.