M
M
Maxim Dunayevsky2014-11-17 17:04:06
Angular
Maxim Dunayevsky, 2014-11-17 17:04:06

What is the correct way to describe AngularJS controllers in different files?

Hello!
I write in the itemsController.js file:

angular.module('SampleApp').controller('ItemsCtrl', function ($scope) {
    //Тут какой-то код
});

Then in another file, usersController.js:
angular.module('SampleApp').controller('UsersCtrl', function ($scope) {
    //Тут уже другой код
});

If I include these scripts, I get an error: Argument 'usersController' is not a function, got undefined . If both controllers are described in one script, everything works without problems. How to describe such a structure correctly? Controllers are independent of each other, located in different parts of the document and do not overlap at all.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
R
Rrooom, 2014-11-17
@Rrooom

You forgot to include usersController.js

A
Alexsey, 2014-11-17
@Ernesto

discover gulp
you can start from this
habrahabr.ru/company/trackduck/blog/230257

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question