What is the safe navigation operator in Angular 6?
In Angular 2, the Safe navigation operator can be used to prevent errors while trying to access the object properties of non-existent objects.
Here’s an example explaining the above statement:
{{ phone?.number }}
This above line of code only evaluates the number when the phone is not null or undefined. This is very suitable in situations where a phone is something that is loading asynchronously.
BY Best Interview Question ON 23 Feb 2020
Example
class PageTest {
public key = true;
}
@Component({
moduleId: module.id,
selector: 'elvis-test',
templateUrl: 'elvis-test.html'
})
export class ElvisTestComp {
@Input() elvisTest?: PageTest;
}
<div>{{elvisTest?.key}}</div>