Angular Ng-options Returning Index Instead Of Object Value October 27, 2022 Post a Comment Below is my ng options Copy HTML: // in this example tutor.fullname is the Label and Value for the select option. <select ng-model="vm.selectedTutor" ng-options="tutor.fullname for tutor in vm.tutors" ></select> Copy Now when you select an option the value will be assigned to $scope.vm.selectedTutor and it wont break your array. Alternatively you can setup a key value pair relationship with your select options like so: Controller: $scope.vm.tutors = [{fullname: "NAME", id: "0"}, {fullname: "NAME2", id:"1"}]; Copy HTML: // in this example tutor.id is the Value and tutor.fullname is the Label for the select option <select ng-model="vm.selectedTutor" ng-options="tutor.id as tutor.fullname for tutor in vm.tutors" ></select> Copy I hope this helps you understand what is going on here a little better, also HERE is a link to the AngularJS documentation. Share Post a Comment for "Angular Ng-options Returning Index Instead Of Object Value"
Post a Comment for "Angular Ng-options Returning Index Instead Of Object Value"