How to make ng-options work with ng-repeat in ion-list

Hi, I’m in the process of creating a “user setting view” and need some help. At the moment my code lists out Car and Motorbike with correct Choices but I’m struggling to get the “default” option to work.

Any suggestions on what I’m doing wrong?

Controller:

.controller('FavoritsCtrl', function($scope,) {
$scope.options = [
            {name: 'Car',
                Choices: [
                    {id:0, name:'Nissan'},
                    {id:1, name: 'Bmw'},
                    {id:2, name: 'Volvo'}
                ],
                default: {id:1, name: 'Bmw'}
            },
            {name: 'Motorbike',
                Choices: [
                    {id:0, name:'Ducati'},
                    {id:1, name: 'Kawasaki'},
                    {id:3, name: 'Yamaha'}
                ],
                default: {id:0, name:'Ducati'}
            },

        ];
})

View:

 <ion-list ng-repeat="item in options">
                <ion-item class="item item-input item-select">
                    <div class="input-label">
                        {{item.name}}
                    </div>
                    <select ng-model="item.default" ng-options="item.name for item in item.Choices">
                    </select>
                    </ion-item>
            </ion-list>
1 Like

I had a hard time understanding this and making it work. After reading this article I was able to solve this kin of problem when working with arrays of objects.

http://www.undefinednull.com/2014/08/11/a-brief-walk-through-of-the-ng-options-in-angularjs/

The default value should reference one of the objects in $scope.options

@joseadrian, the article you provided helped me to solve the problem, thank you.