2

Ok so I have this table which lists all employees and their supervisors in a dropdown. (the first two options in the drop down are always there the other are there depending weather or not they have been selected as a supervisor in the Supervisor Column)

EmployeeTable

Now the issue I'm having is someone can't be selected as his/her own supervisor

on the HTML the table rows are simply created using

ng-repeat="employeeInfo in employees"

and the Drop down select options are loaded like this

ng-options="supervisor.id as (supervisor.name + ' ' + supervisor.lastname + ' ' + supervisor.id) for supervisor in supervisorList"

how do I exclude the person himself in the drop down of available supervisors ?

1 Answer 1

2

UPDATE: EDIT 3 is the working solution


you should add an ng-if like this

ng-repeat="employeeInfo in employees" ng-if="employeeInfo.id!=currentEmployee.id"

(I suppose you have an angular variable currentEmployee that you can use for such a check)

EDIT

try to add this ng-if after the ng-options of the drop down select

ng-options="supervisor.id as (supervisor.name + ' ' + supervisor.lastname + ' ' + supervisor.id) for supervisor in supervisorList" ng-if="employeeInfo.id!=supervisor.id"

EDIT 2

before executing the ng-options that generates the drop down, execute this piece of code

supervisorListCopy = $filter('filter')(supervisorList, function(value, index) {return value.id !== employeeInfo.id;})

then you can generate the drop down using the filtered list

ng-options="supervisor.id as (supervisor.name + ' ' + supervisor.lastname + ' ' + supervisor.id) for supervisor in supervisorListCopy"

EDIT 3

the simplest way to do it is to apply filter aside the ng-options like below

ng-options="supervisor.id as (supervisor.name + ' ' + supervisor.lastname + ' ' + supervisor.id) for supervisor in supervisorListCopy | filter: '!' + employeeInfo.id"
Sign up to request clarification or add additional context in comments.

8 Comments

the ng-repeat is to populate the entire table, I'm looking to remove the option on the drop down, if it is the same as university number on the table row
well, can you share more source code then? so I can refine my answer :)
@LegionDev, I added a new solution
I tried this but if the if Statement is true it removes the entire drop down,and not just that option
@LegionDev, added new solution (EDIT 2), please try it :)
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.