Imagine having an Angular (6+) component structured like this example:
@Component({
selector: 'my-component',
template: '{{test}}'
})
export class MyComponent {
test = 'myData';
constructor() {}
get myData(): string {
return 'this is what I want to display in the template';
}
}
This code snippet showcases a basic concept that highlights the goal at hand. In essence, when the template references {{myData}}
, it triggers the corresponding getter function and displays the anticipated string output. However, if the name of the getter function being called is stored in another variable within the component (such as an array containing multiple options), is there a method for instructing Angular to invoke the appropriate getter based on the value assigned to the variable test
?