Angular Ng-repeat For A Select, Setting One Option As Selected Using $rootScope Variable August 13, 2022 Post a Comment I have the following select: , []); app.controller('MainCtrl', function($scope, $rootScope) { $scope.Labels = {Change_Language_Tooltip: "change lang"}; $scope.Languages_List = [ { name: 'English', Code: 'en' }, { name: 'Espanol', Code: 'es' }, { name: 'Italian', Code: 'it' }]; $rootScope.current_Language = $scope.Languages_List[1]; });Copy <!DOCTYPE html> <html ng-app="app"> <head> <meta charset="utf-8" /> <script src="https://code.angularjs.org/1.3.15/angular.js"></script> <script src="app.js"></script> </head> <body ng-controller="MainCtrl"> <p>selected item is : {{current_Language}}</p> <select class="form-control" onchange="User_Changed_Language()" id="HeaderLanguageSelection" style="cursor:pointer;width:100%;height:30px;margin:0;padding:0" title="{{Labels.Change_Language_Tooltip}}" ng-options="item.name for item in Languages_List track by item.Code" ng-model="current_Language"> </select> </body> </html>Copy PS: the selected item (default or initial) must be one element of the items used in the ngOptions list
Post a Comment for "Angular Ng-repeat For A Select, Setting One Option As Selected Using $rootScope Variable"