1.

What is the safe navigation operator in Angular 6?

Answer»

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.

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>



Discussion

No Comment Found