Reputation: 993
Angular 2 has a 'safe navigation operator' that allows template references to potentially undefined child properties in your components.
Is there any way to use this with dynamic properties and bracket notation? e.g.,
<input [type]="text" [ngModel]="formValues?[control]">
Where control
is another variable from my component telling the template which form value to use and formValues is loaded async so could potentially be null.
Upvotes: 12
Views: 1810
Reputation: 912
I think that you can't, but this is what I'm using, simpler than ngif but empty string and 0 will not do what is after the &&
:
<input [type]="text" [ngModel]="formValues && formValues[control]">
Upvotes: 1