Is safe navigation operator have drawbacks on performance in Angular 2+

480 Views Asked by At

It's known that first ngOnChanges fires before bindings are initialized. So it's common to add safe navigation operator into expressions.

@Component({
    changeDetection: ChangeDetectionStrategy.OnPush,
    selector: 'some-component',
    templateUrl: '<div>{{item?.name}} {{item?.surname}}</div>'
})
export class SomeComponent {

    @Input() item: { name: string; surname: string; };

}

But I guess if that approach have drawbacks on performance. Then would the code below will be faster?

<div *ngIf="item">{{item.name}} {{item.surname}}</div>

Especially for the components with many item?. checks in a template.

0

There are 0 best solutions below