3

i am trying to add a new Module to my application. My HTML for index page is

<body ng-app="com.app">

In my app.js

angular.module('mod1', ['ngResource']);
angular.module('mod2', []); //this is module i want to add
var app = angular.module('com.app', ['ngResource','mod1','mod2']);

My Controllers1.js

var Controllers = angular.module('mod1');
Controllers.controller('ctrl1', function($scope,$http) {});

Controllers.controller('ctrl2', function($scope,$http) {}); //function for module 2

when i try to add this ctrl2 to my "controllers1.js" it works , but if i add this in my other js say "controllers2.js", its not working . My controllers2.js is

'use strict';

var mymodule = angular.module('mod2');

mymodule.controller('ctrl2', function() {

    console.debug("Testing...");

});

summary of my question is : when i try to add my ctrl2 function to new module, its not working and on firefox console i am getting error

Error: Argument 'ctrl2' is not a function, got undefined 
assertArg@http://localhost:8080/tm-webapp/resources/lib/angular.js:1039 
assertArgFn@http://localhost:8080/tm-webapp/resources/lib/angular.js:1050 
@http://localhost:8080/tm-webapp/resources/lib/angular.js:4802 
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

I am stuck here for a long, kindly help me i shall be very thankful. Regards,

2
  • 1
    you should create a plunker so people can help you faster :) Commented Aug 12, 2013 at 8:12
  • you can start with this one : Commented Aug 12, 2013 at 8:30

2 Answers 2

2

Make sure that in your file loader (script tags, requirejs, whatever) Controllers1.js is right next to controllers2.js.

PS: some operating systems / webservers (e.g. the server inside karma on windows) are case sensitive. So try to use same case for your files (either upper or lower).

Sign up to request clarification or add additional context in comments.

2 Comments

Thank you so much, i was just forgetting to add the .js in index.
I ALWAYS do this. I'm favoriting this answer so I don't do this to myself again.
1

You can try this plunker http://plnkr.co/edit/tKIPDQ54JDexB7LAJpDR to see if it works in the way you want.

Comments

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.