Okay so i have an object that contains a few object named as professionals the structure looks like that
lstProf=[{firstName:'tony',lastName:'bob',id:188},{...},{...}];
I want my select field to show firstName + lastName and track by ID
somehow this is not working :
<select class="input-antoine section2-control"
data-ng-options="prof.id as prof.firstName +'
'+prof.lastName for prof in lstProfs track by prof.id"
data-ng-model="patient.treatingProfessionnal"
data-convert-to-number>
</select>
my ng-model is also an int.
what am i doing wrong.
lstProf=[{firstName:'tony',lastName:'bob',id:188},{...},{...}];
<select data-ng-options="prof.id as prof.firstName +'
'+prof.lastName for prof in lstProf track by prof.id"
data-ng-model="personById"
data-convert-to-number>
</select>
First you have typo in the question.
Collection is named lstProf, then you are referencing to it in the ng-options in plural form lstProfs.
Second according to documentation as Pankaj Parkar brought up there is the caution of using select as with track by.
Whatever property is in the track by
, quoting documentation
track by expression is also applied to the ngModel
.
Prepared simple plunker to expose difference of approach to your problem. https://plnkr.co/edit/Rx8JfTee0JnyQa7UD1qE?p=preview