【发布时间】:2017-08-11 04:31:34
【问题描述】:
我已经开始为我参加的 Angular js 课程编写一些代码,并且我在控制台日志中收到此错误(错误:[$controller:ctrlreg]),我不知道为什么?我在 Angular 的网站上查看了它,它说您正在尝试调用一个不存在的控制器,或者类似的东西。我检查并声明了控制器,所以我不知道为什么会出现这个错误。这是我的代码,请帮助,谢谢!
js:
(function () {
'use strict';
angular.module('narrowDownMenuApp', [])
.controller('narrowItDownController ', narrowItDownController )
.service('MenuSearchService', MenuSearchService);
narrowItDownController.$inject = ['MenuSearchService'];
function narrowItDownController(MenuSearchService) {
var menu = this;
menu.input = "";
menu.search = function() {
console.log("blah");
MenuSearchService.getMatchedMenuItems(searchTerm);
}
}
MenuSearchService.$inject = ['$https'];
function MenuSearchService($https) {
var service = this;
service.getMatchedMenuItems = function(searchTerm) {
return $http({
method: "GET",
url: ('https://davids-restaurant.herokuapp.com/menu_items.json')
}).then(function (result) {
console.log(result);
var foundItems
// return processed items
return foundItems;
});
}
}
})();
html:
<!doctype html>
<html ng-app="narrowDownMenuApp">
<head>
<title>Narrow Down Your Menu Choice</title>
<meta charset="utf-8">
<script src="angular.min.js"></script>
<script src="app.js"></script>
</head>
<body>
<div ng-controller='narrowItDownController as menu'>
<h1>Narrow Down Your Chinese Menu Choice</h1>
<div>
<input type="text" placeholder="search term" ng-model="menu.input"> {{menu.input}}
</div>
<div>
<button ng-click="menu.search()">Narrow It Down For Me!</button>
</div>
<!-- found-items should be implemented as a component -->
<found-items found-items="...." on-remove="...."></found-items>
</div>
</body>
</html>
【问题讨论】:
-
.controller('narrowItDownController ', narrowItDownController )删除空格。你看到了吗? -
好的,感谢您的帮助。
标签: javascript angularjs