Supposed that there is a need to use conditional which do the same thing but calling a different method.
const c = true; // for example sake
let b = '';
if (c) {
b = 'method1';
} else {
b = 'method2';
}
function a(){
this.service.b(filter).subscribe((result) =>{
// stuff happens
});
}
Is it possible to use variable b
to be the dynamic variable to call a method from service?
Updated snippet based on the example, I could do the following kind:
if (this.title == 'Students') {
this.studentService.getStudents().then(results=> this.lists = results);
} else {
this.studentService.getCandidates().then(results => this.lists = results);
}
But is it possible to do something like:
this.studentService.get[this.title]().then(results=> this.lists = results);
as the duplicate said it won't work that way.