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.