I am learning AngularJS by making a Todo list app. However, I can't figure out how to use modules from one another.
In detail, I have this code in my app.js:
var app = angular.module('todoApp', [
'ngCookies',
'ngResource',
'ngSanitize',
'ui.router',
'TodoItem'
]);
var TodoItem = angular.module( 'TodoItem' );
app.init = function () {
var item1 = TodoItem.newItem();
item1.title = 'Item 1';
var item2 = TodoItem.newItem();
item2.title = 'Item 2';
app.todoList = [ item1, item2
];
}
app.init();
The module TodoItem is from TodoItem.js, which is:
'use strict';
var TodoItemModule = angular.module('TodoItem', []);
function TodoItemClass() {
this.id = -1;
this.title = '';
this.detail = '';
this.endDate = null;
this.startDate = null;
}
TodoItemModule.newItem = function() {
return new TodoItemClass();
}
In the index.html of the app, I have the following code:
<script src="scripts/app.js"></script>
<script src="scripts/controllers/main.js"></script>
<script src="scripts/controllers/todo.js"></script>
<script src="scripts/models/TodoItem.js"></script>
which I believe doesn't have misspelling in it.
However, I get this error in Chrome Javascript console:
Uncaught Error: [$injector:nomod] Module 'TodoItem' is not available! You either misspelled the module name or forgot to load it. If registering a module ensure that you specify the dependencies as the second argument.
http://errors.angularjs.org/1.2.6/$injector/nomod?p0=TodoItem
So, what did I do wrong here? Thank you very much.