Мой шаблон загружается, но я получаю сообщение об ошибке, которую контроллер не задал. Контроллер существует в моих источниках точно в определенном месте. Что не так с этим кодом?Undefined Controller AngularJS
Error: [ng:areq] http://errors.angularjs.org/1.2.14/ng/areq?p0=ItemsController&p1=not%20aNaNunction%2C%20got%20undefined
at Error (native)
at https://ajax.googleapis.com/ajax/libs/angularjs/1.2.14/angular.min.js:6:450
at xb
Это мой HTML:
<div ng-app="myApp">
<ul ng-controller="ItemsController" class="nav">
<input type="text" value="ItemName" ng-model="newItemName" placeholder="name of new item...">
<button ng-click="addItem()">Add Me</button>
<li ng-repeat="item in items.data" id="item{{item.id}}">
<a href="#">{{item.title}}</a>
<a ng-click="deleteItem($index)" class="fa fa-trash-o"></a>
</li>
</ul>
</div>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.14/angular.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.14/angular-route.js"></script>
<script type="text/javascript" src="js/te.js"></script>
'use strict';
var myApp = angular.module("myApp", []);
myApp.factory("items ", function() {
var items = {};
items.data = [];
return items;
});
myApp.controller("ItemsController", function ItemsController($scope, items) {
$scope.items = items;
$scope.deleteItem = function(index) {
items.data.splice(index, 1);
}
$scope.addItem = function(index) {
items.data.push({
id: $scope.items.data.length + 1,
title: $scope.newItemName
});
}
});
У вас есть ссылка на редактирование вопроса. Вы должны поместить код в описание вопроса, а не в комментарии. –
Является ли js/te.js единственным файлом javascript, который у вас есть? Я предполагаю, что вы создаете myApp в нескольких местах. – DTing
Да, это единственный. – Safa