2016-12-05 186 views
1

我需要獲取組合框上的選定值並顯示它的幫助。附件是一段代碼,顯示了我所嘗試的內容。從組合框中獲取所選值

<label class="col-sm-4 control-label">Issue Type:</label> 
<div> 
    <select ng-model="selectedIssue" ng-options="task as task.calltypename for task in tasktype"><option value="" >Please Select</option></select> 
</div> 
+0

當前的代碼將選定的對象分配給'selectedIssue'財產。如果你需要綁定選定的值而不是選定的對象,那麼'ng-options =「task.calltypeid as task.calltypename .... – Developer

+0

@eldix你爲什麼刪除了答案? – Sajeetharan

+0

我其實想要的值不是對象。謝謝。 –

回答

0

您可以用獲取的選定值

Console.log(selectedIssue.calltypename); 

var app = angular.module('myApp', []); 
 
app.controller('myController', function($scope) { 
 
    $scope.tasktype = [{calltypename :'Outbound'},{calltypename :'Internal'}, {calltypename :'Inbound'}]; 
 
});
<!DOCTYPE html> 
 
<html> 
 
<head> 
 
    <script data-require="[email protected]" data-semver="1.4.7" src="https://code.angularjs.org/1.4.7/angular.js"></script> 
 
    <link rel="stylesheet" href="style.css" /> 
 
    <script src="script.js"></script> 
 
</head> 
 
<body ng-app='myApp' ng-controller="myController"> 
 
<select ng-model="selectedIssue" ng-options="task as task.calltypename for task in tasktype"><option value="" >Please Select</option></select> 
 

 
<label>Selected type:{{selectedIssue.calltypename}}</label> 
 

 
</body> 
 
</html>

0

試試這個示例:

HTML

<div ng-app="App" > 
<div ng-controller="ctrl"> 
<select ng-model="blisterPackTemplateSelected" ng-change="changedValue(blisterPackTemplateSelected)" 
    data-ng-options="blisterPackTemplate as blisterPackTemplate.name for blisterPackTemplate in blisterPackTemplates"> 
    <option value="">Select Option</option> 
</select> 
{{itemList}}  
    </div>  
</div> 

JS

var app=angular.module('App', []); 

function ctrl($scope){ 
    $scope.itemList=[]; 
    $scope.blisterPackTemplates=[{id:1,name:"a"},{id:2,name:"b"},{id:3,name:"c"}] 

    $scope.changedValue=function(item){ 
    $scope.itemList.push(item.name); 
    }  

} 

以下爲輸出

enter image description here

希望它可以幫助你。

1

下面是HTML代碼,希望這有助於

<html> 
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script> 
<body> 

<div ng-app="myApp" ng-controller="myCtrl"> 

<select ng-model="selectedIssue" ng-options="item as item.calltypename for item in names"> 
</select> 
<label>Issue type:{{selectedIssue.calltypename}}</label> 

</div> 

<script> 
var app = angular.module('myApp', []); 
app.controller('myCtrl', function($scope) { 
    $scope.names = [{calltypename:'Emil'},{calltypename:'Emily'}, {calltypename:'Emial'}]; 
}); 
</script>