0
我已閱讀關於此問題的多篇文章,本網站上給出的解決方案似乎對我無效。我有一個選擇框有幾個選項,我需要一個默認值顯示給用戶。目前沒有選擇任何選項。這段代碼可能有什麼問題。使用AngularJS在選擇框選項上選擇默認值
HTML
<select class="form-control input-sm" name="collegeTranscripts1" id="collegeTranscripts1" data-ng- model='transcriptCAdata.typeAccepted' data-ng-options='option.value as option.name for option in typeOptions1'></select>
JS
$scope.typeOptions1 = [
{ name: 'Please Select', value: 'selected' },
{ name: 'Official', value: 'OFFICIAL' },
{ name: 'Unofficial', value: 'UNOFFICIAL' },
{ name: 'None', value: 'NONE' }
];
$scope.form = {type : $scope.typeOptions1[0].value};
的NG-模型必須被NG-模型= 'transcriptCAdata.typeAccepted' – jmccommas 2014-09-24 17:20:47
爲什麼難道不這項工作:$ scope.transcriptCAdata = {typeAccepted:$ scope.typeOptions1 [0]。價值}; – jmccommas 2014-09-24 17:21:15
如何:$ scope.transcriptCAdata = {typeAccepted:$ scope.typeOptions1 ='selected'}; – jmccommas 2014-09-24 17:24:18