Thank you for the reply @Nicolas.

I solved my problem using ng-options in another way:

ng-options="item.value as item.key for item in vm.Units"

Using this approach, the angular only returns the value of selected option.
Using ng-options with "track by", the angular returns the entire selected
object.

See my plunkr:
http://plnkr.co/edit/Rm076Li6WQ0tDU57PWxV?p=preview

On Thu, Feb 5, 2015 at 6:36 PM, Nicholas Smith <[email protected]> wrote:

> Sorry there was a copy-paste typo, the $scope.Units = example the Values
> should have been 11, 22, 33...  See plnkr for exact code.
>
>
> On Thursday, February 5, 2015 at 2:35:10 PM UTC-6, Nicholas Smith wrote:
>>
>> I'm not really clear on what you're trying to do, but I've started a
>> plnkr.  Does the $scope.Units data look like what you're using?
>>
>> http://plnkr.co/edit/yv7RM7OkcSTLWPbDcvqh?p=preview
>>
>> I've got $scope.Units declared as:
>>
>>         $scope.Units = [
>>           {Id: 1, Name: 'Product Name 1', UnitId: { Key: "Option 1",
>> Value: 10 }},
>>           {Id: 2, Name: 'Product Name 2', UnitId: { Key: "Option 2",
>> Value: 20 }},
>>           {Id: 3, Name: 'Product Name 3', UnitId: { Key: "Option 3",
>> Value: 30 }},
>>           {Id: 4, Name: 'Product Name 4', UnitId: { Key: "Option 4",
>> Value: 40 }},
>>           {Id: 5, Name: 'Product Name 5', UnitId: { Key: "Option 5",
>> Value: 50 }}
>>           ];
>>       });
>>
>>
>> With the select as:
>>
>> <select ng-model="unitId" ng-options="u.UnitId.Key for u in Units track
>> by u.UnitId.Value"></select>
>>
>> It renders select options such as:
>>
>> <select ng-model="unitId" ng-options="u.UnitId.Key for u in Units track
>> by u.UnitId.Value" class="ng-pristine ng-valid ng-touched">
>>   <option value="?" selected="selected"></option>
>>   <option value="11" label="Option 1">Option 1</option>
>>   <option value="22" label="Option 2">Option 2</option>
>>   ....
>>
>>
>>
>>
>>
>> On Thursday, February 5, 2015 at 1:00:47 PM UTC-6, Gustavo Cruz wrote:
>>>
>>> Hi people,
>>>
>>> I have a select with ng-options like below:
>>>
>>> <select ng-model="vm.Product.UnitId" ng-options="item.Key for item in
>>> vm.Units track by item.Value">
>>>
>>> My source comes from an array of Key/Values. Each item is a object:
>>>
>>> {
>>>    Key: "My option text",
>>>    Value: "1"
>>> }
>>>
>>> So, my final model render as:
>>>
>>> {
>>>    Id: 0,
>>>    Name: 'Product Name',
>>>    UnitId: { object }   -> *my problem goes here, I need this property
>>> flat, only with the selected value in the dropdown, not as object.*
>>> }
>>>
>>>
>>> How to achieve this?
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>  --
> You received this message because you are subscribed to the Google Groups
> "AngularJS" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To post to this group, send email to [email protected].
> Visit this group at http://groups.google.com/group/angular.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"AngularJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.

Reply via email to