olivier olivier - 2 months ago 12
AngularJS Question

Use third party library in a angular factory

This is my factory:

.factory('DataService',['$http',function($http, Backand ){
var data = [];
return {
GetData: function(){
return $http.get(Backand.getApiUrl() + '/1/objects/details').then(function(response){
data = response;
return response;
GetElem: function(personId){
if(data[i].id == personId){
return data[i];


Now the problem. The third party library
is correctly injected but i get the error:
Cannot read property 'getApiUrl' of undefined

So Backand is undefined. When i use Backand in a controller everything work just fine.

What should i do to fix this?


You are missing Backand while injecting

Change this:

.factory('DataService',['$http',function($http, Backand ){

To This:

.factory('DataService',['$http', 'Backand',function($http, Backand ){

Hope this will work for you.