나는 Todo 목록 응용 프로그램을 만들어 AngularJS를 배우고 있습니다. 그러나, 나는 서로에게서 모듈을 사용하는 방법을 이해할 수 없다. 상세AngularJS에서 다른 모듈의 함수를 사용하는 방법은 무엇입니까?
, 내 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();
입니다 TodoItem
이 TodoItem.js
에서 인 모듈 : 응용 프로그램의 index.html
에서
'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();
}
, 나는 다음과 같은 한 코드 :
<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>
wh 나는 그것이 틀렸다고 믿지 않는다.
그러나, 나는 크롬 자바 스크립트 콘솔에서이 오류를 얻을 :
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
그래서, 제가 여기에 잘못 했는가? 고맙습니다.
이 도움이 될 수 있습니다 내가 그 두 위대한 건축의 시작 포인트를 추가 할 것입니다 각 개발자 자신을 통해 찾을 수 있습니다 https://github.com/yeoman/generator-angular. – ossek