How To Select An Option In A Dropdown List Angularjs October 26, 2023 Post a Comment I am using AngularJS directive and I need to set a selected option of a dropdown list in my template. Solution 1: The way you are doing your ng-options it will store the name of the option in scope.energy not the whole option. You were on the right track when you did:scope.energy = scope.energyOptions[0];CopyBut it won't work because it expects scope.energy to be the name and not the whole option. What you want to do in your ng-options is something like:<select id="energySource" ng-options="o as on.name for o in energyOptions" ng-model="energy" ng-selected="energy" ng-change="energyChange();"></select> CopyThe important change is the addition of the o as o.name. The 'o' on the left is what will actually be selected and stored in your scope.energy, while the as o.name is the text that will be displayed on your pull down. Solution 2: Make sure the scope.energy is outside your initialization.$scope.energyOptions = [ { name: "test1", id: "Electricity" }, { name: "test2", id: "Gas" }, { name: "test3", id: "Water" }, { name: "test4", id: "Solar" }]; $scope.energy = $scope.energyOptions[2]; Copy Share Post a Comment for "How To Select An Option In A Dropdown List Angularjs" Top Question How To Detect Android's Version Number In Firefox For Android? For a website we want to show a link in the play store if t… Display Array Of Objects In A Dynamic Table Javascript I want to display an array of objects in a dynamic table us… Modal Appears On Page Load Following is my code but the modal only appears when someon… D3 Animating A Bubble Chart Within A Given Radius //bubble chart base. http://jsfiddle.net/NYEaX/1450/ I am t… Passport-Google-OAuth Callback Not Working When Used In Web Service I Have used Passport-Google-OAuth in Node.js web service pr… Synchronized Multiple API Calls I need to fetch the data from two different API endpoints, … Passport-Google-OAuth Callback Not Working When Used In Web Service I Have used Passport-Google-OAuth in Node.js web service pr… Javascript Regex Phone Validation Can anyone suggest a js function to validate a phone number… How To Place " ...view More " Text Next To The Truncated Sentence In A Container-Javscript I want to show a '...more' text for a long name des… How To Limit The Html Table Records In Each Page I am populating a table in my jsp which has more than 20 re… December 2024 (1) November 2024 (38) October 2024 (54) September 2024 (18) August 2024 (210) July 2024 (191) June 2024 (388) May 2024 (673) April 2024 (428) March 2024 (767) February 2024 (917) January 2024 (771) December 2023 (793) November 2023 (313) October 2023 (520) September 2023 (286) August 2023 (325) July 2023 (280) June 2023 (373) May 2023 (206) April 2023 (138) March 2023 (144) February 2023 (184) January 2023 (259) December 2022 (129) November 2022 (233) October 2022 (154) September 2022 (165) August 2022 (502) July 2022 (287) June 2022 (294) Menu Halaman Statis Beranda © 2022 - JavaScript Info