how to update attribute from select in angularjs

I'm using Angularjs and rails to build a site. The page is managing a Foo object and Foo has a name field and a definition field.

in my edit page I am working on Foo object 1 and I have a select (drop down) control with a list of the existing Foo objects in it to select from (it would make sense to filter out the current Foo object)

if the user selects an existing Foo object from the select I don't want to change which Foo object I'm editting, I just want the current Foo object's definition field to update with the definition field contents from the selected Foo object (from the select box).

I currently have a select defined as such: (and obj is the Foo object I'm working on)

<select id="foo_list{{obj.id}}" ng-model="obj.definition"
      ng-options="d.name for d in existing_foos | orderBy:'name'" 
      ng-change="changeFooDefinition()">
</select>

in the changeFooDefinition() method I want to update the current obj.definition with the definition of the Foo object selected.

What the current code does is change which Foo object I'm working on in the whole form. I just want to copy the selected definition to the current objects definition. how can I do that?

thanks in advance,

Max

Currently you have $scope.obj.definition bound to a Foo object, not just the definition of the foo object. What you need to do is bind the selected Foo object to another scope variable, and then set obj.definition equal to the definition of this new variable (which should be a Foo object).

HTML:

<select id="foo_list{{obj.id}}" ng-model="selectedFoo" 
    ng options="d.name for d in existing_foos | orderBy:'name'" 
    ng-change="changeFooDefinition()">
</select>

JS:

myApp.controller('Ctrl', ['$scope, function($scope) {
    $scope.obj = { name: 'currFoo', definition: 'changePls', id: 333 };

    $scope.existing_foos = [ 
        { name: 'foo1', definition: 'first foo', id: 1 },
        { name: 'foo2', definition: '2nd foo', id: 2 },
        {name: 'foo3', definition: '3rd foo', id: 3 }
    ];

    $scope.changeFooDefinition() {
        obj.definition = selectedFoo.definition;
    }
}]);

See it working here: http://jsfiddle.net/ADukg/2120/

Let me know if I misunderstood what you were asking and if so hopefully I can fix my answer accordingly.