Home>

I am renovating an application made with AngularJs on the screen side.
I want to get the ID of the item selected in the select menu, but the html display shows the item's No and name.
Currently, the information that has been passed to the server side is No.
No is a value that the user can change, so if a duplicate occurs, an error will occur, so I want to get an ID to avoid this.

AngularJs version: 1.3.0

<select
    ng-model = "item.exampleNo"
    ng-options = "'' + c.exampleNo as (c.exampleNo + ':' + c.name) for c in item.exampleList"
    ng-disabled = "false"
    required>
</select>

Options contents

$scope.exampleList = [
    {name: "A", exampleNo: "1", exampleId: "101"},
    {name: "B", exampleNo: "2", exampleId: "102"},
    {name: "C", exampleNo: "3", exampleId: "103"},
    {name: "D", exampleNo: "4", exampleId: "104"},
    {name: "E", exampleNo: "5", exampleId: "105"}
    ];


I thought that the contents of the array can be obtained because it contains an ID,
It could not be acquired as ng-model = "item.exampleId".
You can get the ID, but you can get the name and pass it to the server side.
* I tried to get the name with ng-model = "item.name" but could not get it.
Please teach me.

  • Answer # 1

    Self-solved.
    Id was successfully obtained by changing "c.exampleNo" in ng-options of html to "c.exampleId".

    ng-options = "'' + c.exampleId as (c.exampleNo + ':' + c.name) for c in item.exampleList"
                   ^^^^^^^^^^^

    I'm sorry.

Related articles