错误:参数'ModalDemoCtrl'不是函数,没有定义

Error: Argument 'ModalDemoCtrl' is not a function, got undefined

本文关键字:定义 函数 ModalDemoCtrl 参数 错误      更新时间:2023-09-26

嗨,当我在我的项目中使用angularJS时,我得到了上述错误。我使用django框架为我的整个项目。所以我没有任何额外的js文件为我的项目。以下是我的代码。

JS:

{{ ngapp }}.controller("ModalDemoCtrl", function ($scope, $http, $cookies, $resource, $log, $modal) {

                                $scope.items = ['item1', 'item2', 'item3'];
                                $scope.animationsEnabled = true;
                                $scope.open = function (size) {
                                var modalInstance = $modal.open({
                                animation: $scope.animationsEnabled,
                                templateUrl: 'myModalContent.html',
                                controller: 'ModalInstanceCtrl',
                                size: size,
                                resolve: {
                                items: function () {
                                return $scope.items;
                                }
                                }
                                });
                                modalInstance.result.then(function (selectedItem) {
                                $scope.selected = selectedItem;
                                }, function () {
                                $log.info('Modal dismissed at: ' + new Date());
                                });
                                };
                                $scope.toggleAnimation = function () {
                                $scope.animationsEnabled = !$scope.animationsEnabled;
                                };
                                });
                                // Please note that $modalInstance represents a modal window (instance) dependency.
                                // It is not the same as the $modal service used above.
                                {{ngapp}}.controller('ModalInstanceCtrl', function ($scope, $modalInstance, items) {
                                $scope.items = items;
                                $scope.selected = {
                                item: $scope.items[0]
                                };
                                $scope.ok = function () {
                                $modalInstance.close($scope.selected.item);
                                };
                                $scope.cancel = function () {
                                $modalInstance.dismiss('cancel');
                                };
                                });

和我的html的一部分(它太长了,这就是为什么):

<div class="well" ng-controller="ModalDemoCtrl">
        <script type="text/ng-template" id="enable.html">
    </script>
        <button type="button" class="btn btn-info" ng-click="open('lg')">blahh</button>&nbsp </div>
谁能告诉我这里出了什么问题?我已经想了很长时间了。我不知道如何处理这个问题。

依赖关系应该被推断出来,但也许可以尝试注入$scope和其他类似的。

controller("ModalDemoCtrl", ['$scope','$http','$cookies', '$resource', '$log', '$modal', function ($scope, $http, $cookies,   $resource, $log, $modal) { 
...
}]);