Reputation: 3560
I have one issue.when i am fetching values from database and try to set those values on html view using angular.js.I am explaining my code below.
My controller file contains the following code.
$http({
method: 'POST',
url: "php/homeuserrole/editRoleData.php",
data:userdata,
headers: { 'Content-Type': 'application/x-www-form-urlencoded' }
}).then(function successCallback(response){
//console.log('edited data',response.data[0].user_role);
$scope.user_role=response.data[0].user_role;
$scope.user_name.value=response.data[0].user_name;
$scope.buttonName="Update";
},function errorCallback(response) {
});
Inside the success function i am binding the values to following html view.
<div class="input-group bmargindiv1 col-md-12">
<span class="input-group-addon ndrftextwidth text-right" style="width:180px">User Name :</span>
<select id="coy" name="coy" class="form-control" ng-model="user_name" ng-options="user.name for user in listOfName track by user.value" >
<!--<option value="">Select course</option>-->
</select>
</div>
</div>
<div class="col-md-6">
<!--<div class="input-group bmargindiv1 col-md-12">
<span class="input-group-addon ndrftextwidth text-right" style="width:180px">Login Name :</span>
<input type="text" name="itemname" id="contactno" class="form-control" placeholder="add Login Name" ng-model="login_name" >
</div>-->
<div class="input-group bmargindiv1 col-md-12">
<span class="input-group-addon ndrftextwidth text-right" style="width:180px">User Role :</span>
<select id="coy" name="coy" class="form-control" ng-model="user_role" >
<option value="">Select User Role</option>
<option value="Princpal">Princpal</option>
<option value="HOD">HOD</option>
<option value="Lab Assistance">Lab Assistance</option>
<option value="Professor ">Professor</option>
<option value="Ast.Professor ">Ast.Professor</option>
</select>
</div>
</div>
Here i am able to set value in first dropdown list(i.e-user name
) but the value can not be set at second dropdown list(i.e-user Role
).it is showing blank when that success function is executing.Please help me to resolve this issue.
Upvotes: 0
Views: 157
Reputation: 2243
I think, you need to also mention ng-options in the second dropdown too. Similar like this -
ng-options="user.name for user in listOfName track by user.value"
Upvotes: 1