假设这是我的控制器:
function MainController(BaseInformation, baseInformationConstants) {
var vm = this;
getGenders();
function getGenders() {
vm.genders = BaseInformation.list({headerId: baseInformationConstants.genderId});
}
}
和这个select标签,我想用ng-init
为它设置默认值,但它没有用:
<select ng-init="vm.user.genderId = {id: vm.genders[0].id}"
ng-model="vm.user.genderId"
ng-options="gender.id as gender.topic for gender in vm.genders track by gender.id">
</select>