Angular Ng-repeat For A Select, Setting One Option As Selected Using $rootscope Variable July 27, 2023 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><htmlng-app="app"><head><metacharset="utf-8" /><scriptsrc="https://code.angularjs.org/1.3.15/angular.js"></script><scriptsrc="app.js"></script></head><bodyng-controller="MainCtrl"><p>selected item is : {{current_Language}}</p><selectclass="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>CopyPS: 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"