[SalesForce] how to retrieve an attribute value in ternary operator

i have two attributes in my component:

<aura:attribute name="sObjectName" type="String" />
<aura:attribute name="acc" type="Account" />

the attribute sObjectName contains the sObjectName (Lead, Account, Contact etc)
the attribute acc contains an Id,Name,Type.

when i write this line

<label>{!v.acc.Id}</label>

i receive the id of the account and it works great

when i write this line:

<label>{!v.sObjectName=='Lead' ? 'txtTest' : !v.acc.Id}</label>

when im in the lead record, it print 'txtTest' just fine, but when i'm not – it prints 'false' and not !v.acc.Id

what am i doing wrong? what is the correct syntax? Thanks

Best Answer

The reason that you are getting false is that the v.acc.Id is a javascript string, and the logical negation operator, !, returns false when applied to strings.

var s = 'string'; 
console.log(s);   // string
console.log(!s);  // false

Basically, all you need to do is remove the !:

<label>{!v.sObjectName=='Lead' ? 'txtTest' : v.acc.Id}</label>