Does it says that using Safe Navigation Operator will not render(update) data which was null at first but eventually got changed say because of AJAX call updated that object after some time?

No. It means that the expression is not evaluated after it detects some null value (but won't stop from rendering if it changes in the future to some non-null value).

For example if in component.ts you have

val = null;
// ...
someService.someMethod().susbcribe(val => this.val);

and in the component.html you have

{{val?.someProperty}}

Initially nothing will be rendered because val is null.

Now, once some value arrives inside the susbcribe and this.val gets some non-null value, the value of val.someProperty is rendered in the view.

See a demo using a timeout.

Answer from lealceldeiro on Stack Overflow
🌐
Medium
medium.com › @zayani.zied › safe-navigation-operator-optional-chaining-js-and-angular-d253431a2625
Safe Navigation Operator-Optional Chaining (JS and Angular) | by Zied ZAYANI | Medium
February 20, 2023 - To use the safe navigator operator, you just need to add (?.) after the object and before the property or the function needed. ... Of course, in an Angular application, we can use the safe navigation operator with TypeScript, and we have the ...
🌐
ConcretePage
concretepage.com › angular-2 › angular-2-pipe-operator-and-safe-navigation-operator-example
Angular Pipe Operator (|) and Safe Navigation Operator (?.) - ConcretePage.com
Safe navigation operator avoids exception for null and undefined values in property paths. While accessing properties from object it may throw exception if object is null or undefined.
🌐
GitHub
github.com › angular › angular › issues › 9850
Safe navigation operator executes members after "?." even if not needed · Issue #9850 · angular/angular
April 13, 2016 - If we want to access street in the template even though, contact is loaded asynchronously, we can use the safe navigation operator for that. But we need to apply it on every nested property because Angular doesn't ignore the rest of an expression after a ?..
Published   Jul 06, 2016
🌐
Medium
medium.com › @garfunkel61 › unwrapping-angulars-safe-navigation-operator-7641434aa29d
Unwrapping Angular’s Safe Navigation Operator | by Andy Dłubak | Medium
August 22, 2023 - Wouldn’t it be reassuring to know there’s water inside? In Angular, the safe navigation operator (aka the “Elvis operator”) acts as a reassurance. It’s a way of checking if there’s “water in the pool” before taking the leap.
🌐
NGCC in Angular Ivy
iq.js.org › questions › angular › what-is-safe-navigation-operator
What is safe navigation operator?
November 11, 2025 - The safe navigation operator(?)(or known as Elvis Operator) is used to guard against null and undefined values in property paths when you are not aware whether a path exists or not.
🌐
C# Corner
c-sharpcorner.com › article › introduction-to-safe-navigation-operator-in-angular-2
Introduction To Safe Navigation Operator In Angular 2
December 1, 2016 - Conclusion The Safe Navigation Operator is very useful to protect against null and undefined values in the property paths. In this article, we also learned the alternatives of this operator and the advantages of this operator over alternatives.
🌐
Coderwall
coderwall.com › p › ohcuda › avoid-the-safe-navigation-operator-in-angular
Avoid the Safe Navigation Operator in Angular (Example)
August 16, 2018 - #angular · #operator · #typescript · The Safe Navigation Operator, AKA the Elvis Operator, can help reduce code by ensuring that an object is not null before accessing a property of it.
🌐
Amitthakkar
amitthakkar.github.io › Safe-Navigation-Operator
Safe Navigation Operator by AmitThakkar
Safe Navigation Operator(?.) is used to avoid error Cannot read property 'propertyName' of undefined.
Find elsewhere
🌐
Bennadel
bennadel.com › blog › 3043-providing-default-values-for-the-safe-navigation-operator-in-angular-2-beta-8.htm
Providing Default Values For The Safe Navigation Operator In Angular 2 Beta 8
April 21, 2020 - In Angular 2, the "Elvis operator" (really, the safe navigation operator) allows an object path to be safely navigated in situations in which you are not entirely sure if every object in the path exists.
🌐
Howjavascriptworks
howjavascriptworks.com › home › demystifying the safe navigation operator in angular
Safe Navigation Operator Angular: Learn More
November 2, 2023 - The Safe Navigation Operator, also known as the “Elvis Operator”, comes as a savior, ensuring that accessing a property of an undefined object doesn’t crash your application. Imagine stepping on a loose brick on a path – it’s unexpected and disruptive. This operator is like a guardian, ensuring you sidestep that brick. You’ll often see it in action as ‘object?.property’. Here, if the ‘object’ is null or undefined, Angular stops there, ensuring no errors are thrown.
🌐
DEV Community
dev.to › pssingh21 › safe-navigation-operator-bang-bang-bang-192j
Safe Navigation Operator? Bang! Bang Bang!! - DEV Community
March 12, 2021 - In this case, the compiler does not keep track that map.has() has been evaluated while evaluating map.get(). So the compiler can't determine if the map returns a safe value. This can also be used in terms of calling a possibly undefined function and array indexes. ... For example it could be used when using React refs. When using refs, the current value may be null if the element is unmounted. In JavaScript every value is assocaiated as either a truthy value or a falsy value. So, a bang(!) as a prefix on a value acts as a logical "not" operator on that value.
🌐
Jasmine Conseil
jasmineconseil.com › home › safe navigation operator - optional chaining (js and angular)
Safe navigation operator - optional chaining (JS and angular)
March 27, 2024 - To use the safe navigator operator simply add (?.)after the object and before the required property or function. ... Of course, in an Angular application, we can use the secure navigation operator with TypeScript, and we have the option of using ...
Top answer
1 of 7
247

! is non-null assertion operator (post-fix expression) - it just saying to type checker that you're sure that a is not null or undefined.

the operation a! produces a value of the type of a with null and undefined excluded


Optional chaining finally made it to typescript (3.7)

The optional chaining operator ?. permits reading the value of a property located deep within a chain of connected objects without having to expressly validate that each reference in the chain is valid. The ?. operator functions similarly to the . chaining operator, except that instead of causing an error if a reference is nullish (null or undefined), the expression short-circuits with a return value of undefined. When used with function calls, it returns undefined if the given function does not exist.

Syntax:

obj?.prop // Accessing object's property
obj?.[expr] // Optional chaining with expressions
arr?.[index] // Array item access with optional chaining
func?.(args) // Optional chaining with function calls

Pay attention:

Optional chaining is not valid on the left-hand side of an assignment

const object = {};
object?.property = 1; // Uncaught SyntaxError: Invalid left-hand side in assignment
2 of 7
164

Since TypeScript 3.7 was released you can use optional chaining now.

Property example:

let x = foo?.bar.baz();

This is equvalent to:

let x = (foo === null || foo === undefined)
  ? undefined
  : foo.bar.baz();

Moreover you can call:

Optional Call

function(otherFn: (par: string) => void) {
   otherFn?.("some value");
}

otherFn will be called only if otherFn won't be equal to null or undefined

Usage optional chaining in IF statement

This:

if (someObj && someObj.someProperty) {
  // ...
}

can be replaced now with this

if (someObj?.someProperty) {
  // ...
}

Ref: https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-7.html

🌐
GitHub
github.com › angular › angular › issues › 17181
feat: add bracket access to safe navigation operator · Issue #17181 · angular/angular
April 15, 2017 - angular / angular Public · Notifications · You must be signed in to change notification settings · Fork 27k · Star 99.7k · New issueCopy link · New issueCopy link · Closed · Closed · feat: add bracket access to safe navigation operator#17181 · Copy link · Labels ·
Published   Jun 02, 2017