0

我預讀取功能,在我的項目:如何在輸入文本框中設置默認選擇值?

<input type="text" 
ng-model="customPopupSelected" 
placeholder="Custom popup template" 
uib-typeahead="state.id as state.desc for state in states | filter:{name:$viewValue}" 
class="form-control"> 

這裏是Plunker。 如何在默認情況下選擇id = 4的sample_data?

+0

對不起,但我不完全理解的問題和代碼不匹配Plunker。您是否嘗試將模型值初始化爲匹配id:「4」的「sample_data」數組中的對象? – WonderGrub

回答

0

您可以初始化模式:

angular.forEach($scope.sample_data, function(item, index) { 
    if (item.id == 4) { 
     $scope.monkey = $scope.sample_data[index] 
    } 
} 

Fiddle

相關問題