Angular Ng-options Returning Index Instead Of Object Value November 30, 2023 Post a Comment Below is my ng options $scope.vm.tutors = [{fullname: "NAME"}, {fullname: "NAME2"}]; $scope.vm.selectedTutor = ""; // you can assign a value if you would like to have an option preselected.CopyHTML: // 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> CopyNow 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"}]; CopyHTML: // 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> CopyI 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"