gpt4 book ai didi

javascript - 错误 : [$controller:ctrlreg] after declaring controller?

转载 作者:行者123 更新时间:2023-11-30 21:16:36 25 4
gpt4 key购买 nike

我已经开始为我参加的 angular js 类(class)编写一些代码,但我在控制台日志中收到此错误(错误:[$controller:ctrlreg]),我不确定为什么?我在 angular 的网站上查看了它,它说你正在尝试调用一个不存在的 Controller ,或者类似的东西。我检查了一下,我已经声明了 Controller ,所以我不知道为什么会出现这个错误。这是我的代码,请帮忙,谢谢!

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 名称中有空格。删除它,您的 Controller 将工作

 angular.module('narrowDownMenuApp', [])
.controller('narrowItDownController', narrowItDownController )

关于javascript - 错误 : [$controller:ctrlreg] after declaring controller?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45627003/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com