Reputation: 531
I call a function
getData('serviceName', 'functionName')
That function looks like
function getData(service, functionName){
service.functionName(request, $root.thing).then()
}
But I always get service.function is not a function, how do I call them properly?
Upvotes: 2
Views: 115
Reputation: 2265
If you use bracket notation you can achieve what you want
function getData(service, functionName){
service[functionName](request, $root.thing).then()
}
Upvotes: 2
Reputation: 1686
function getData(service, functionName){
var yourservice = $injector.get(service);
yourservice.yourActualfunctionName(request, $root.thing).then()
}
You can sure use your service as string ,Use it like this.Make sure you inject $injector wherever you are using it. not sure about function name because function is not in same file.
Upvotes: 0