Safe navigation operator .?
This is the documentation for Angular 7.
You can switch to the latest version Angular 10.
You can switch to the latest version Angular 10.
The Angular safe navigation operator (?.
) is a fluent and convenient way to guard against null
and undefined
values in property paths.
Here it is, protecting against a view render failure if the currentHero
is null:
The current hero's name is {{currentHero?.name}}
It works perfectly with long property paths:
The current hero's name is {{currentHero?.info?.name}}
And methods:
The current hero's name is {{currentHero?.getInfo()?.name}}
Links & Tutorials