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.
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]">
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With