I want to call a variable dynamically.
export class AppComponent {
my_a_variable = 'test a';
my_b_variable = 'test b';
type = 'a'; // this variable value will come from another place dynamically.
}
In my html i need something like
<div>{{my_{{type}}_variable}}</div>
I know it can be solved with an assoc array but I can't use this here. Can you please help?
Thanks.
Hope this works,
export class AppComponent {
my_a_variable = 'test a';
my_b_variable = 'test b';
type = 'a';
}
In your template you can do like this,
<div>{{this['my_' + type + '_variable']}}</div>
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