Total Pageviews

2014/03/13

Error: ng:areq Bad Argument

Problem
I have a html page with 2 tabs.

As I entered this page, it occurred javascript errors with "Error: ng:areq" and link to this page: http://docs.angularjs.org/error/ng/areq?p0=fms435rTab1Controller&p1=not%20a%20function,%20got%20undefined


Trace the Problem
There are three html files to consist of this page. Each html file have its own JavaScript file, and will be imported by mail page.

fms435r.js
 (function() {  
   var app = angular.module("fms435rApp", [ 'ntaCommonModule' ]);  
 })();  

fms435rTab1.js
(function() {  
   var app = angular.module("fms435rApp");  
   app.factory('fms435rService', function(cResource) {  
     return {};  
   });  
   app.controller('fms435rTab1Controller', function($scope, fms435rService,  
       stateManager, alerter, userHolder) {      
   });  
 })(); 

fms435rTab2.js
 (function() {  
   var app = angular.module("fms435rApp", [ 'ntaCommonModule' ]);  
   app.factory('fms435rService', function(cResource) {  
     return {};  
   });  
   app.controller('fms435rTab2Controller', function($scope, fms435rService,  
       stateManager, alerter, userHolder) {  
   });  
 })();  

Root Cause
The problem result from fms435rTab2.js. 
It misuse angular.module, because it create a new module, not to retrieve.
Therefore, you should fix it as bellows:
 (function() {  
   var app = angular.module("fms435rApp");  
   app.factory('fms435rService', function(cResource) {  
     return {};  
   });  
   app.controller('fms435rTab2Controller', function($scope, fms435rService,  
       stateManager, alerter, userHolder) {  
   });  
 })(); 

Here is the syntax
ParamTypeDetails
namestring
The name of the module to create or retrieve.
requires
(optional)
Array.=
If specified then new module is being created.
If unspecified then the module is being retrieved for
further configuration.
configFnFunction
Optional configuration function for the module.
 Same as Module#config().

Reference
[1] http://docs.angularjs.org/api/ng/function/angular.module

No comments: