1

I'm trying to write a simple service following this tutorial. The code for adding the new service is:

'use strict';
var projectModule = angular.module('project',[]);
projectModule.factory('Team', function() {  
    return {
        thing : {
            x : 100
        }
    };
});

My controller code is:

var Controllers = angular.module('fixedTeam',[]);
Controllers.controller('controller', function ($scope,$http,$location,Team) {
    $scope.getFixedTeam = function(){
        console.debug(Team.thing);
    }
});

When I load the view, I get the following error:

Error: Unknown provider: TeamProvider <- Team
createInjector/providerInjector<@http://localhost:8080/tm-webapp/resources/lib/angular.js:2734
getService@http://localhost:8080/tm-webapp/resources/lib/angular.js:2862
createInjector/instanceCache.$injector<@http://localhost:8080/tm-webapp/resources/lib/angular.js:2739
getService@http://localhost:8080/tm-webapp/resources/lib/angular.js:2862
invoke@http://localhost:8080/tm-webapp/resources/lib/angular.js:2880
instantiate@http://localhost:8080/tm-webapp/resources/lib/angular.js:2914
@http://localhost:8080/tm-webapp/resources/lib/angular.js:4805
update@http://localhost:8080/tm-webapp/resources/lib/angular.js:14198
Scope.prototype.$broadcast@http://localhost:8080/tm-webapp/resources/lib/angular.js:8307
updateRoute/<@http://localhost:8080/tm-webapp/resources/lib/angular.js:7463
qFactory/defer/deferred.promise.then/wrappedCallback@http://localhost:8080/tm-webapp/resources/lib/angular.js:6846
qFactory/defer/deferred.promise.then/wrappedCallback@http://localhost:8080/tm-webapp/resources/lib/angular.js:6846
qFactory/ref/<.then/<@http://localhost:8080/tm-webapp/resources/lib/angular.js:6883
Scope.prototype.$eval@http://localhost:8080/tm-webapp/resources/lib/angular.js:8057 
Scope.prototype.$digest@http://localhost:8080/tm-webapp/resources/lib/angular.js:7922 
Scope.prototype.$apply@http://localhost:8080/tm-webapp/resources/lib/angular.js:8143 
done@http://localhost:8080/tm-webapp/resources/lib/angular.js:9170 
completeRequest@http://localhost:8080/tm-webapp/resources/lib/angular.js:9333 
createHttpBackend/</xhr.onreadystatechange@http://localhost:8080/tm-webapp/resources/lib/angular.js:9304 

What am I doing wrong?

5
  • Please clarify Controllers in your second snippet. How is it defined? Commented Aug 1, 2013 at 10:30
  • Controllers.controller should probably be projectModule.controller Commented Aug 1, 2013 at 10:31
  • @stevuu i have added it. "var Controllers = angular.module('fixedTeam',[]); Commented Aug 1, 2013 at 10:32
  • Then you need to add projectModule as a dependency as @Codezilla shows in his answer. Commented Aug 1, 2013 at 10:37
  • @stevuu it gives another error, kindly see comments on codezilla answer. Commented Aug 1, 2013 at 10:44

1 Answer 1

5

Need to add the dependent module:

var Controllers = angular.module('fixedTeam',['project']);
Sign up to request clarification or add additional context in comments.

1 Comment

it gives me now " Error: No module: projectModule [Break On This Error] throw Error('No module: ' + name);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.