devzero devzero - 5 months ago 24
Javascript Question

How do I use angular to chose what item is editable from a dropdown

So I have an array of elements

$scope.customerList = [];


Then I want to select an item and edit it

<select id="customerSelect" ng-model="customer" ng-options="item as item.Customer for item in customerList track by item.Customer"></select>


And I have a form where I edit it

<div>
<label for="customer">Kundenavn</label> <input id="customer" ng-model="customer.Customer" />
</div>
<div>
<label for="Account">Konto</label> <input id="Account" ng-model="customer.Account" />
</div>


The idea is of course that when I edit the item, the item in the list is updated, unfortantly this does not seem to be the case. What is the best way to get this kind of functionality from angular?

Answer

The problem is the tracking "track by item.Customer" witch I then change in the input in the form.

The trick was to remove "track by" entirerly, it then worked as expected.

<select id="customerSelect" ng-model="customer" ng-options="item as item.Customer for item in customerList"></select>