Safe navigation operator .?
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