“未定义 ctrls”错误不确定在哪里定义它
Posted
技术标签:
【中文标题】“未定义 ctrls”错误不确定在哪里定义它【英文标题】:"ctrls is not defined" error not sure where to define it 【发布时间】:2016-07-09 17:55:46 【问题描述】:我收到 CTRLS is not defined 错误,我不知道在哪里定义 ctrls。我完全是 angularJS 的菜鸟,我正在尝试调用烂番茄 API 来搜索电影。我将在哪里定义 CTRLS,我将如何编写代码?
angular.module('demoApp',[])
.constant('apiKey', 'removed for security' )
.constant('http://api.rottentomatoes.com/api/public/v1.0')
document.getElementById('searchBox').addEventListener('keydown', function (event)
if (event.which === 13 || event.keyCode === 13)
// construct the uri with our apikey
var searchText = this.value;
console.log('Enter works');
ctrls.controller('resultsCTRL', function ($scope, $http)
$scope.search = searchText;
console.log('control function works');
$http.jsonp('http://api.rottentomatoes.com/api/public/v1.0/movies.json',
params:
q: 'toy',
page_limit: 10,
page: 1,
apikey: apiKey,
callback: 'JSON_CALLBACK'
);
);
;
);
【问题讨论】:
ctrls
未定义。
【参考方案1】:
ctrls 未定义。所以你需要定义引用哪个模块。
这应该可以帮助您:https://docs.angularjs.org/guide/controller
此处复制的示例供参考:
var myApp = angular.module('myApp',[]);
myApp.controller('DoubleController', ['$scope', function($scope)
$scope.double = function(value) return value * 2; ;
]);
<div ng-controller="DoubleController">
Two times <input ng-model="num"> equals double(num)
</div>
【讨论】:
【参考方案2】:您使用 ctrls 的方式就像您最初将 AngularJS 模块存储到变量中一样。
例如:
var ctrls = angular.module('demoApp', []);
ctrls
.constant('apiKey', 'removed for security' )
.constant('http://api.rottentomatoes.com/api/public/v1.0')
ctrls.controller(function($scope, $http)
//Logic Here
);
【讨论】:
以上是关于“未定义 ctrls”错误不确定在哪里定义它的主要内容,如果未能解决你的问题,请参考以下文章
TypeError:无法解构“对象(...)(...)”的属性“setValues”,因为它未定义。 (反应/创建反应应用)
反应使用上下文。无法解构“对象(...)(...)”的属性“currentChatbotInEdit”,因为它未定义。我该如何解决?