I have the following in my angular controller
MyUserService.getUserRoles().then(function (data) {
var userInValidRole = false;
var role1 = "Role1";
var role2 = "Role2";
if ((data.indexOf(role1) > -1) || data.indexOf(role2 ) > -1) {
userInValidRole = true;
}
This is working as expected. However I was hoping to do something like:
var validRoles = ["Role1", "Role"];
and then check
if ((data.indexOf(validRoles) > -1)) {
userInValidRole = true;
}
However it is not working as expected - is there something I have done wrong?
var validRoles = ["Role1", "Role"];last element typo: Role2validRolesis another array. That's not howindexOfworks.userInValidRole = data.indexOf(role1) > -1 || data.indexOf(role2) > -1;datacould have multiple roles, right? So if the user has role1 and role3, you're searching the list ['Role1', 'Role3'] to see if any of the elements are equal to the entire list ['Role1', 'Role'].validRoles.indexOf()for each value indata