-1

I have the following arrays:

owner_users = [{username : "sam", name:"Sampath", email:"xyz" },
{username : "ram", name:"Ram Mohan", email:"asd" },
{username : "shyam", name:"Shyam pandey", email:"wer" }]

and

admin_users = [{username : "sam", name:"Sampath", email:"xyz" },
{username : "pandey", name:"Mangal Pandey", email:"yuy" },
{username : "ameer", name:"Gajini", email:"tyrt" },
{username : "shyam", name:"Shyam pandey", email:"wer" }]

and

test_users = [{username : "kiran", name:"Kiran", email:"kiran" },
{username : "pandey", name:"Mangal Pandey", email:"yuy" },
{username : "balu", name:"Balakrishna", email:"balu.krsh" },
{username : "shyam", name:"Shyam pandey", email:"wer" }] 

I am making ng-repeat of project_details in a table. project_details array is with object properties -- project_type, owner_name, comment. for owner_name i have to list this combination of user types in ng-options. Like if project_type is new then i have to show combined list of owner_user and test_users. if project_type is old, then i have to show combined list of owner_users and admin_users without duplicates.

How can I achieve this in angularJS?

Sampath
  • 90
  • 1
  • 11
  • 2
    What have you done so far? – Mistalis Aug 04 '16 at 12:26
  • bro please give more info or else check the related questions http://stackoverflow.com/questions/23595034/removing-duplicates-from-angular-js-ng-options-ng-repeat http://jsfiddle.net/YJQx6/5/ – Sa E Chowdary Aug 04 '16 at 12:40

1 Answers1

0

First, I used concat function to make the arrays combined for each of the possible project_type.

Ex: old_project_users = owner_users.concat(admin_users);

To remove duplicates, i used the unique filter from AngularUI (source code available here: AngularUI unique filter) and use it directly in the ng-options.

To show users list based on conditions, i used ng-if inside ng-repeat for select tag keeping inside a div.

Ex:

 <div ng-if="project_type ='new'">
    <select ng-model="project.owner" ng-options="user.username for user in new_project_users| unique:'username'">       
    </select>
    </div>
<div ng-if="project_type ='old'">
    <select ng-model="project.owner" ng-options="user.username for user in old_project_users| unique:'username'">       
    </select>
    </div>
Sampath
  • 90
  • 1
  • 11