javascript - TypeError: Cannot read property 'objects' of undefined -


i error typeerror: cannot read property 'objects' of undefined want iterate throw array, find current id. guess can't use $scope inside services ? how can correctly define $scope ?

objects getting factory ussing http method.

app.service('sharedservice', function (inventory, user, tags) {  var allinventories = inventory.query(); var alltags = tags.query(); var allusers = user.query();  return {      getinventory: function() {         return allinventories;     },     setinventory: function(inventoryvalue){         allinventories = inventoryvalue;     },     gettags: function() {         return alltags;     },     settags: function(tagsvalue){         alltags = tagsvalue;     },       getuser: function(){         return allusers;     },     setuser: function(uservalue){         allusers = uservalue;     },      findbyid: function findbyid($scope, id) {                     for(var = 0; < $scope.info.objects.length; i++){                         if($scope.info.objects[i].id == id){                             return $scope.info.objects[i];                         }                      }                     return null;                 }     };   }); 

instead of passing scope can pass info object , separate sevice , controller .

 findbyid: function findbyid(info, id) {                     for(var = 0; < info.objects.length; i++){                         if(info.objects[i].id == id){                             return info.objects[i];                         }                      }                     return null;                 }     }; 

and in controller call method correct parameter,

sharedservice.findbyid($scope.info); 

and make sure calling function inside success event of $http call since getting data http method.


Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -