Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add multiple values to disabled attribute in Angular

Tags:

angular

I am trying to add values to a disabled directive. So if you look at the code below I am disabling a button if a value matches System Admin. I am now trying to add more values to this. So I want to add System Admin and HR Manager to this.

[disabled]="userRole === 'System Admin'"

I tried this but it does not seem to work

[disabled]="userRole === 'System Admin' || 'HR Manager'"
like image 339
RRB Avatar asked Jun 08 '26 11:06

RRB


1 Answers

If you have many conditions to check then its better to write a function which will return true or false:

HTML:

[disabled]="isDisabled(userRole)"

Typescript:

isDisabled(userRole:string):boolean {
  if(userRole == "System Admin" || userRole == "HR Manager") {
    return true
  }
  return false
} 
like image 145
Adrita Sharma Avatar answered Jun 11 '26 05:06

Adrita Sharma