1

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?

1
  • its shame my openID is not working again and I have to open stackexchange account to ask this question, don't know any other way, any idea how can I link my openID account with this one, so I can use both authentication(openID & stackexchange), if one does not work, I can use other. Commented Jul 24, 2013 at 11:44

1 Answer 1

4

You have to modify your html as below and then it will work with your foreign key

<select ng-model="customer" ng-options="c.id as c.name for c in customers">

 $scope.customer = 9;
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.