how to set default value after ng-options complete

2019-07-24 22:04发布

assume that this is my controller:

function MainController(BaseInformation, baseInformationConstants) {
    var vm = this;
    getGenders();

    function getGenders() {
        vm.genders = BaseInformation.list({headerId: baseInformationConstants.genderId});
    }
}

and this select tag, that i want to set default value for it with ng-init, but it didn't worked:

<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>

0条回答
登录 后发表回答