javascript / beginner
Snippet
Safe Navigation Operator (?.)
The safe navigation operator prevents errors when accessing properties of an object that might be null or undefined. It stops the evaluation if a reference is missing.
snippet.js
1
<img [src]="user?.profile?.avatarUrl">
angular
Breakdown
1
user?.profile
If 'user' is null, the expression returns null instead of throwing a 'cannot read property of null' error.
2
[src]="..."
This is Property Binding, which sets the image source attribute dynamically.