Assume, following JSON Structure is existing:
[
{
"role_id": 1,
"role_name": "Admin"
},
{
"role_id": 2,
"role_name": "Editor"
}
]
and stored in $rootScope.roles.
What I need is:
$rootScope.roles[index -> where role_id == 2].rolename // gets -> Editor
How can I do that in Angular?
ng-lodash is an elegant way:
role_name = lodash.pluck(lodash.where($rootScope.roles,{'role_id': 2 }),'role_name');