In view I have
...
<select ng-model="customer" ng-options="c.name for c in customers">
<option value="">-- chose customer --</option>
</select>
....
In controller I have
$scope.customers = [
{"id":4,"name":"aaaa","isActive":1,"isDeleted":0},
{"id":5,"name":"testxyz","isActive":0,"isDeleted":0},
{"id":9,"name":"bbb","isActive":1,"isDeleted":0},
{"id":10,"name":"asdfa","isActive":0,"isDeleted":0},
{"id":11,"name":"asdfa","isActive":0,"isDeleted":0}
];
if ($scope.$id != null)
{
Message.query({id: $scope.$id}, function(data) {
if (data[0].id) {
$scope.name = data[0].name;
$scope.fromName = data[0].fromName;
$scope.subject = data[0].subject;
// this line does not work because data[0].custID is database
// customer ID Foreign Key linked with this record
// {"id":4,"name":"aaaa","isActive":1,"isDeleted":0}
$scope.customer = data[0].custID;
// this works as it is based on index
//$scope.customer = $scope.customers[3];
} else {
alert('Request Failed: ' + data.msg);
}
});
}
Now when I try to edit the record and open view in edit mode with pre-filled fields from database, I will need to do default selection to SELECT Box which works fine on array index based but I need to do selection on Foreign Key bases
How can I default select Select box based on Foreign key, not index?