I'm refactoring some angular code and I want to separate things by type (controllers in a controllers folder, etc.).
I have two controllers and an app.js file. Why am I getting, and what does this undefined is not a function mean (I get an error in the console from both of my separate controller files)
app.js
var app = angular.module('myApp',['myApp.controllers']);
controllers
app.module('myApp.controllers').controller('DocumentController',function($scope){
$scope.message = "This is the message from Document controller";
})
//
app.module('myApp.controllers').controller('MyController', function ($scope) {
$scope.message = "This is the message from My Controller";
})
HTML
<!DOCTYPE html>
<html ng-app="myApp">
<head lang="en">
<meta charset="UTF-8">
<title></title>
<script src="lib/jquery-1.9.1.js"></script>
<script src="lib/angular-1.2.js"></script>
<script src="app.js"></script>
<script src="controllers/MyController.js"></script>
<script src="controllers/DocumentController.js"></script>
</head>
<body>
this is from the index.html page
<div ng-controller="MyController">
{{message}}
</div>
<script>
</script>
</body>
</html>
Uncaught Objecterror for both my controllersapp.controller(...and skip the injection. Otherwise you need to create a module properly with dependencies argument