I am newbie to angular. Currently all of my controllers are defined in following controllers.js file on following patterns
function A($scope){.....}
function B($scope){.....}
function MainCtrl($http) {.....}
.
.
.
angular
.module('myApp')
.controller('A', A)
.controller('B', B)
.controller('MainCtrl', MainCtrl)
Things are working fine. But now, i want to create separate .js file for each controller. Have created a directory named controllers under root and added A.js and B.js there
A.js looks like following
var app = angular.module('myApp', []);
app.controller('A', ['$scope', function ($scope) {
.
.
.
}]);
controllers.js file is already been added to index.html
<script src="js/controllers.js"></script>
<script src="controllers/A.js"></script>
and now when i add A.js or B.js files in index.html it throws error saying MainCtrl isn't defined. But it's sure it's defined in controllers.js. I can see following link in console.
http://errors.angularjs.org/1.5.0/ng/areq?p0=MainCtrl&p1=not%20a%20function%2C%20got%20undefined
Can anybody suggest some solution