WhoAmI
WhoAmI

Reputation: 317

Show json array list in drop down angular

I am new in AngularJS and trying to show data in drop down list and facing few errors. Here is my JSON data:

$scope.list=[
{
    "$id": "1",
    "Groups": [
        "xyz",
        "abc",
        "ugh",
        "ccd"
    ]
}
]

I am trying to show list of names of Groups mentioned in the json.

In controller :-

$scope.selectedval = $scope.list[0].Groups;
console.log($scope.selectedval);

In View I am doing this :-

ng-options="item.Groups for item in list"

By doing this I am getting all the datas in single option. How to separate datas on each list by ng-option ?

Upvotes: 0

Views: 650

Answers (3)

praveen kumar
praveen kumar

Reputation: 1524

`ng-options="item for item in list[0].Groups"

Upvotes: 1

Mhd Wael Jazmati
Mhd Wael Jazmati

Reputation: 667

$scope.list:[{"$id": "1",
"Groups": [
    "xyz",
    "abc",
    "ugh",
    "ccd"
]}]
$scope.list=[] // replace ":" by "="

Upvotes: 0

Sudhir Ojha
Sudhir Ojha

Reputation: 3305

In view try this

ng-options="val for val in selectedval"

Upvotes: 1

Related Questions