Answer the question
In order to leave comments, you need to log in
How to initialize SELECT with a value and not an object?
the actual subject
plnkr.co/edit/M0C84exBn1Uf6U8xuWxr
is a blank here. where is the mistake?
it is necessary that during initialization in $scope.select was id=1, but at the same time the select was selected.
<select ng-model='select' ng-init="select = types[0].id"
ng-options='type.id as type.name for type in types track by type.id'></select>
<div>{{select}}</div>
$scope.types = [{
id: 1,
name: 'test1'
}, {
id: 2,
name: 'test2'
}, {
id: 3,
name: 'test3'
}, {
id: 4,
name: 'test4'
}, ];
Answer the question
In order to leave comments, you need to log in
I found the solution myself, removed ng-options 'track by type.id' at the end
Very clumsy decision. The select is bound to the 'select' field, here in the controller and set the desired initial value:
$scope.types = [{
id: 1,
name: 'test1'
}, {
id: 2,
name: 'test2'
}, {
id: 3,
name: 'test3'
}, {
id: 4,
name: 'test4'
}, ];
$scope.select = $scope.types[1];
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question