2016-07-28 27 views
0

選擇以下是我的代碼:如何使我的第一個元素在數據列表過濾結果,被自動

<input required class="input form-control" type="text" ng-model="select.mySelect" list="bloodgroups" placeholder="Select Blood Group"> 
<datalist id="bloodgroups" > 
    <option ng-repeat="bloodgroup in bloodgroups"> {{bloodgroup.bloodgroups}} 
</datalist> 
+0

你需要任何進一步的幫助或澄清?如果我的回答有幫助,請將其標記爲已接受。 –

回答

0

JS

$scope.options = [{ name: "a", id: 1 }, { name: "b", id: 2 }]; 
$scope.selectedOption = $scope.options[1]; 

HTML

<select data-ng-options="o.name for o in options" data-ng-model="selectedOption"></select> 


其他示例:

這是從外部源(url)檢索數據(GET)的情況。 Something.thisismydata來自factory

對於ng-model="select.mySelect"是這樣的:

$scope.showDataOnSelect = function() { 
     var url = "http://example.com/api"; 
       Something.thisismydata(function(data) { 
        $scope.thisismydata = data; 
        $scope.select.mySelect = $scope.thisismydata[0].id; 
       }, url); 
      } 

$scope.showDataOnSelect(); 
相關問題