Javascript &引用;未定义ctrls”的定义;错误:不确定在何处定义它

Javascript &引用;未定义ctrls”的定义;错误:不确定在何处定义它,javascript,angularjs,Javascript,Angularjs,我得到一个CTRL未定义错误,我不知道在哪里定义CTRL。我是angularJS的一个彻底的noob,我正在尝试调用烂番茄API来搜索电影。我将在哪里定义CTRL以及如何编写代码 angular.module('demoApp',[]) .constant('apiKey', 'removed for security' ) .constant('http://api.rottentomatoes.com/api/public/v1.0') document.getElementByI

我得到一个CTRL未定义错误,我不知道在哪里定义CTRL。我是angularJS的一个彻底的noob,我正在尝试调用烂番茄API来搜索电影。我将在哪里定义CTRL以及如何编写代码

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'                    
                }
            });
        });
    };
});

CTRL未定义。因此,您需要定义引用的模块

这将有助于您:

此处复制的示例仅供参考:

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>
var myApp=angular.module('myApp',[]);
myApp.controller('DoubleController',['$scope',函数($scope){
$scope.double=函数(值){返回值*2;};
}]);
二次等于{{double(num)}}

使用CTRL的方式就像最初将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。