[英]Can not get the value after selecting from drop down list using Angular.js
我有一個問題,我無法使用Angular.js從下拉列表中獲取值。 我在下面解釋我的代碼。
<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);
}
在這里,當我從丟失的下拉菜單中選擇值並單擊任何按鈕時,在該函數內部,我無法使用此控制台獲得任何值console.log('check',$scope.user_name.value);
我需要檢索所選的值。請幫助我。
看看Shb的評論。 您使用參數'user_name'
它是一個字符串)調用方法(在ng-change上) removeBorder
。 但是,您需要名為user_name
的變量。 因此,將您的方法調用更改為removeBorder(user_name)
。
編輯:
該代碼正在運行。 見這個笨蛋 。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.