简体   繁体   English

无法使用angular.js将值设置为下拉选择的值

[英]Can not set value as dropdown selected value using angular.js

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. 我有一个问题。当我从数据库中获取值并尝试使用angular.js在html视图上设置这些值时,我在下面解释我的代码。

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. 在成功函数内部,我将值绑定到以下html视图。

<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( ie-user name ) but the value can not be set at second dropdown list( ie-user Role ).it is showing blank when that success function is executing.Please help me to resolve this issue. 在这里我可以在第一个下拉列表( ie-user name )中设置值,但不能在第二个下拉列表( ie-user Role )中设置值。执行该成功功能时它显示为空白。请帮助我解决此问题。

I think, you need to also mention ng-options in the second dropdown too. 我认为,您还需要在第二个下拉列表中提及ng-options。 Similar like this - 像这样-

ng-options="user.name for user in listOfName track by user.value"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM