我想設置默認值使用angularjs下拉列表。我粘貼下面的代碼。 這是視圖模型代碼和HTML代碼:如何使用angularjs將默認值設置爲下拉列表viewmodel
appmodule.factory("testpage1ViewModel", function() {
function Testpage1ViewModel() {
this.SearchContainer1 = {
cmbGender:''
};
this.message = '';
this.SearchContainer1_Master_cmbGender = {
ValidValues: [
{ id: '1', name: 'Male' },
{ id: '2', name: 'Female' },
{ id: '3', name: 'Transgender' }
],
DefaultValue: { id: '1', name: 'Male' }
};
}
return Testpage1ViewModel;
});
<select name="cmbGender"
class="form-control"
ng-options="option.name for option in viewModel.SearchContainer1_Master_cmbGender.ValidValues track by option.id"
ng-model="viewModel.SearchContainer1.cmbGender"></select>
與上述代碼一樣,從視圖模型中獲取的值列表。我添加完整的viewmodel。 – venkat