Home > OS >  Ternary Javascript for HTML (Angular)
Ternary Javascript for HTML (Angular)

Time:09-24

how can I change the following to ternary so I can use it in .HTML file

if (statusChange && statusChange === 'Employed') {
  return true;
} else {
  return employmentStatus === 'Employed'
}

i.e. assign the result of the second comparison only if the first if statement results to false

CodePudding user response:

Simply:

return statusChange && statusChange === 'Employed' ? true : employmentStatus === 'Employed'

CodePudding user response:

No need for ternary operation here, just use the or operation:

statusChange === 'Employed' || employmentStatus === 'Employed'

If the first part is true, the whole expression will return true. If it's false, it will check it the second part is true or false

Much cleaner

  • Related