D
D
Demid Borodin2014-12-22 01:19:34
Angular
Demid Borodin, 2014-12-22 01:19:34

Angular Select how to get only key value?

There is a form.

<form name="create-workpeople" ng-submit="createWorkpeople()">
    <select ng-model="workpeople.workpeopleType" ng-options="workerType.type for workerType in workpeopleType "></select>
</form>

the default value for select is this
$scope.workpeopleType = [
        {type: 'P'},
        {type: 'V'},
        {type: 'N'},
        {type: 'U'}
    ];

    $scope.workpeople.workpeopleType = $scope.workpeopleType[0].type;

if we display our $scope.workpeople in its entirety
{{workpeople | json}}
, we get JSON like this, which is what I need.
{
  "workpeopleType": "P"
}

I can't seem to get my head around ng-option. I try like this
<select ng-model="workpeople.workpeopleType" ng-options="workerType.type for workerType in workpeopleType "></select>

And when changing the value, JSON is already obtained like this
"workpeopleType": {
    "type": "P"
  }

How to get rid of Type and leave only P. Please do not throw slippers.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
_
_ _, 2014-12-22
@demidborodin

ng-options="workerType as workerType.type for workerType in workpeopleType"

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question