Asked 8 years ago
30 Sep 2016
Views 1441
andy

andy posted

service is undefined - error in Angular js




 mainapp=angular.module('OpenApp',   ['ngRoute','ngResource']);
}]); mainapp.config(['$resourceProvider', function($resourceProvider) {
  // Don't strip trailing slashes from calculated URLs
  $resourceProvider.defaults.stripTrailingSlashes = false;
}]);
mainapp.factory("UserService", function ($resource)
  {
  
  return $resource('user-detail.php?id=:id&format=jsonuser', {id:'@id'});

});

mainapp.controller('UController', ['$routeParams', function BookCtrl($routeParams,UserService) {
 //id will be dynamic 
    UserService.get({id:34
  });
  this.params = $routeParams;
   }]);


got error
Error: UserService is undefined
its simple . you forget to pass 'UserService' to controller - Mitul Dabhi  
Oct 3 '16 06:38
Mahesh Radadiya

Mahesh Radadiya
answered Nov 30 '-1 00:00

pass 'Userservice' to controller .it will solve "service is undefined error"




mainapp.controller('UController', ['$routeParams','Userservice' function BookCtrl($routeParams,UserService) {
 //id will be dynamic 
    UserService.get({id:34
  });
  this.params = $routeParams;
   }]);
Post Answer