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,

4

2 回答 2

2

确保在您的文件加载器(脚本标签、requirejs 等)Controllers1.js中紧挨着controllers2.js.

PS:一些操作系统/网络服务器(例如windows上业力内的服务器)区分大小写。因此,请尝试对您的文件使用相同的大小写(大写或小写)。

于 2013-08-12T08:16:33.440 回答
1

你可以试试这个 plunker http://plnkr.co/edit/tKIPDQ54JDexB7LAJpDR看看它是否以你想要的方式工作。

于 2013-08-12T08:31:44.783 回答