Angular JS controller in an external file

1,242 views
Skip to first unread message

CannotCode

unread,
Dec 16, 2014, 3:09:35 PM12/16/14
to ang...@googlegroups.com
Hello everybody!

I am currently working on a simple web application and decided to go with AngularJS. 
My problem is that when I put the Angular controller into a separate js file, the app cannot find thse files and thus angular does not work.
I know that my angular works as it is fine if I put a script into my jsp file straight. 

There is a detail that might be a reason: whenever I check the Network of my code in the browser, the js files that are not found considered to 
have a text/html type. Might that be a problem and if yes, how should I solve it? Not sure if I should post any code. If needed, will be provided.

Thank you in advance. 

CannotCode

unread,
Dec 16, 2014, 3:27:59 PM12/16/14
to ang...@googlegroups.com

Justin Walsh

unread,
Dec 17, 2014, 1:01:03 AM12/17/14
to ang...@googlegroups.com
Hi, 

In app.js you have declared a dependency on a module (vApp.controller), but this module has not been defined:
var app = angular.module('vApp', ['vApp.controller']);


In UserControllers.js change the following line (which retrieves the module with the name vApp)
var app= angular.module('vApp');

to this, which defines a module with the name vApp.controller (with no dependencies):
var app= angular.module('vApp.controller', []);


Also - you are mixing controllerAs syntax with the traditional syntax.  If you want to use the controllerAs syntax (Hello as first), then:
 app.controller('Hello', ['$scope', function ($scope) {
     
       
this.id = 'ID';
       
this.content = 'some stuff';
   
}]);

Regards
Justin

kevin rey Baquiran

unread,
Dec 17, 2014, 1:04:42 AM12/17/14
to ang...@googlegroups.com
Hi did you add your js file inside your dom?.

Justin Walsh

unread,
Dec 17, 2014, 1:05:55 AM12/17/14
to ang...@googlegroups.com

kevin rey Baquiran

unread,
Dec 17, 2014, 1:06:21 AM12/17/14
to ang...@googlegroups.com
Hi ,

Check your code on your dom. maybe you forget to add this js file on the script on the dom.


On Wednesday, December 17, 2014 12:09:35 AM UTC+4, CannotCode wrote:

CannotCode

unread,
Dec 17, 2014, 5:45:44 PM12/17/14
to ang...@googlegroups.com
Thank you very much. The code you gave is really working, but undortunately, the files still cannot be found. So I am not sure what I should do about it

среда, 17 декабря 2014 г., 7:01:03 UTC+1 пользователь Justin Walsh написал:

CannotCode

unread,
Dec 17, 2014, 5:46:34 PM12/17/14
to ang...@googlegroups.com
Thank you, I will try that when I understand how I can find the dom file

среда, 17 декабря 2014 г., 7:06:21 UTC+1 пользователь kevin rey Baquiran написал:
Reply all
Reply to author
Forward
0 new messages