I've got a simple factory passing data gathered from Mongolab into one controller, but I can't get it in another.
app.factory('User', function ($mongolabResourceHttp) {
return $mongolabResourceHttp('users');
});
I've also got a Goal factory just like this. Both work fine as-is.
The above factory is working fine in my userCtrl, but I can't add it into my goalCtrl. I've got a userguid that I want to attach to goals. Basically: click link to user goals, create goals, userguid becomes part of saved goal.
app.controller('goalCtrl', function ($scope, $location, goals, users) {
$scope.goals = goals;
$scope.users = users;
$scope.new = function () {
$location.path('/');
};
...
});
Any clues would be much appreciated. Thanks.
(I asked a similar question earlier today, but I think it had too many issues going on and it didn't get any responses. I have since worked out one of the issues and this question is to narrow it down further. So this isn't a complete repeat. Sorry if it bugs anyone though.)
You need to inject the service into your controller using the actual service name of 'User':
app.controller('goalCtrl', function ($scope, $location, goals, User) {
$scope.users = User;
I'd also read up on angular service and dependency injection when you get a chance.