简体   繁体   English

使用Angular.js从下拉列表中选择后无法获取值

[英]Can not get the value after selecting from drop down list using Angular.js

I have an issue.I can not fetch value from drop down list using Angular.js. 我有一个问题,我无法使用Angular.js从下拉列表中获取值。 I am explaining my code below. 我在下面解释我的代码。

    <select class="form-control"  id="user_name" ng-model="user_name" ng-options="user.name for user in listOfUser track by user.value " >
    </select>
<input type="button" class="btn btn-success" ng-click="sendEvoucherCode();"  id="addProfileData" value="SEND"/>

$http({
            method:'GET',
            url:"php/getUserId.php",
            headers: { 'Content-Type': 'application/x-www-form-urlencoded' }
        }).then(function successCallback(response){
            //console.log('user id',response);
            angular.forEach(response.data,function(data){
                var obj={'name':data.userid,'value':data.userid};
                $scope.listOfUser.push(obj);
            })
        },function errorCallback(response) {
        })

$scope.sendEvoucherCode=function(){
        console.log('check',$scope.user_name);

    }

Here when i am selecting value from drop down lost and clicked on any button,inside that function i can not get any value bu using this console console.log('check',$scope.user_name.value); 在这里,当我从丢失的下拉菜单中选择值并单击任何按钮时,在该函数内部,我无法使用此控制台获得任何值console.log('check',$scope.user_name.value); .Here i need to retrive the selected value.Please help me. 我需要检索所选的值。请帮助我。

Take a look to Shb's comment. 看看Shb的评论。 Your calling the method (on ng-change) removeBorder with the parameter 'user_name' which is a String. 您使用参数'user_name'它是一个字符串)调用方法(在ng-change上) removeBorder But you want the variable named user_name . 但是,您需要名为user_name的变量。 So change your method call to removeBorder(user_name) . 因此,将您的方法调用更改为removeBorder(user_name)

EDIT: 编辑:

The code is working. 该代码正在运行。 See this plunker . 见这个笨蛋

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

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