javascript - Can not set selected value in select tag using angular.js and PHP -
i have 1 issue regarding select tag in angular.js.i binding data in select tag dynamically coming database.here unable set selected default text in select tag.i explaining code below.
role.html:
<select id="coy" name="coy" class="form-control" ng-model="user_name" ng-options="user.name user in listofname track user.value" > </select>
my controller code set value inside select tag given below.
$scope.listofname=[]; $scope.listofname=[{ name: 'user name', value: '' }] $http({ method: 'get', url: "php/userrole/getuserdata.php", headers: { 'content-type': 'application/x-www-form-urlencoded' } }).then(function successcallback(response){ angular.foreach(response.data,function(obj1){ var user={'name':obj1.user_name,'value':obj1.user_name}; $scope.listofname.push(user); }); },function errorcallback(response) { });
here able fetch data , bind them inside select tag here not able show user name
default selected text means no default selected text coming after data bind.please me.
try this:
angular.foreach(response.data, function(obj1) { var user = { 'name': obj1.user_name, 'value': obj1.user_name }; $scope.listofname.push(user); }); $scope.user_name = $scope.listofname[0];
Comments
Post a Comment