← Back to Blogs

Importance of ELVIS Operator in Angular Template HTML

Chandan Luthra Aug 18, 2020 12:00:00 AM ~

Use the ELVIS Operator to check for 'undefined' keys/fields in HTML templates, ensuring safe access to object properties that may or may not be present.

Importance of ELVIS Operator in Angular Template HTML

Key takeaways

  • Loading takeaways…

ELVIS Operator can be used to check “undefined” on keys/fields/properties in html template file, Its means when you access keys in objects. And in object, some keys may be available or not. like Example.

results :
{
“name” : “Mohan”,
“emailId” : “mohan563@gmail.com”,
“gender” : “male”
}

Suppose, I want to access “emailId” key in template html file of an Angular project, for e.g “results.emailId“, here “results.emailId” key is always available in JSON object then its not compulsory use to ELVIS Operator. But in case the keys does not exists then ELVIS Operator comes to rescue us by applying a safe referencing to the JSON object e.g. “results?.emailId“. The “?.” operator allows to use the JSON keys that are not present. It will results in a “null” value.

Pravin kumar

pravin(d0t)kumar(at the rate)enveu(d0t)com

Chandan Luthra - Director, Product Engineering, Enveu
Chandan Luthra is a co-founder of Enveu, and heads the Engineering department at Enveu. He is an early adopter of OTT tech and has been part of many OTT platforms across the globe. He is developing & building Products and SaaS platforms for more than 13+ years

Add a Comment

Your email address will not be published. Required fields are marked *

Want this capability in your OTT?

See how Enveu’s Experience Manager helps teams launch faster, operate efficiently, and improve discovery and monetization.