我的应用程序中的AngularJs $ injector错误

时间:2017-03-01 20:38:30

标签: angularjs angularjs-injector

由于Error: $injector:modulerr Module Error

,我目前因应用程序崩溃而遇到问题

完整错误是:

    Failed to instantiate module app due to:
    Uncaught Error: [$injector:modulerr] Failed to instantiate module app due to:
Error: [$injector:modulerr] Failed to instantiate module JobCtrl due to:
Error: [$injector:nomod] Module 'JobCtrl' is not available! You either misspelled the module name or forgot to load it. If registering a module ensure that you specify the dependencies as the second argument.
http://errors.angularjs.org/1.6.2/$injector/nomod?p0=JobCtrl
    at http://ep-dev3/CPDManagement/app/Vendor/angular.js:69:20
    at http://ep-dev3/CPDManagement/app/Vendor/angular.js:2188:31
    at ensure (http://ep-dev3/CPDManagement/app/Vendor/angular.js:2112:46)
    at module (http://ep-dev3/CPDManagement/app/Vendor/angular.js:2186:24)
    at http://ep-dev3/CPDManagement/app/Vendor/angular.js:4757:36
    at forEach (http://ep-dev3/CPDManagement/app/Vendor/angular.js:358:34)
    at loadModules (http://ep-dev3/CPDManagement/app/Vendor/angular.js:4741:13)
    at http://ep-dev3/CPDManagement/app/Vendor/angular.js:4758:54
    at forEach (http://ep-dev3/CPDManagement/app/Vendor/angular.js:358:34)
    at loadModules (http://ep-dev3/CPDManagement/app/Vendor/angular.js:4741:13)
http://errors.angularjs.org/1.6.2/$injector/modulerr?

我的app.js和我的控制器都有ui.bootstrap作为依赖项。当我尝试从控制器中删除依赖项时,应用程序会中断。如果我离开它,它运行正常,但给我添加服务和指令的问题。

app.js:

    angular.module('app',
    [
        'JobCtrl',
        'JobSvc',
        'WebsiteCtrl',
        'WebsiteSvc',
        'myClientCtrl',
        'ClientSvc',
        'MediaCompanyCtrl',
        'MediaCompanySvc',
        'PageAlertSvc',
        'ui.bootstrap',
        'Common'
    ]
);

控制器:

    angular.module('app')
    .controller('JobCtrl',
            [
                'JobService',
                'WebsiteService',
                'MediaCompanyService',
                'ProductService',
                '$scope',
                '$uibModal',
                'PageAlertService',
                function (JobService, WebsiteService, MediaCompanyService,
                    ProductService, $scope, $uibModal,PageAlertService){
                                     /** Stuff in my controller **/
             }]);

编辑显示来源

    <!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>@ViewBag.Title - CPD Management Tool</title>
    <script src="~/app/Vendor/angular.min.js"></script>
    <script src="~/Scripts/ui-bootstrap-tpls-2.5.0.min.js"></script>
    @Styles.Render("~/Content/css")
    @Scripts.Render("~/bundles/modernizr")

</head>
<body>
@if (User.Identity.IsAuthenticated )
{
    <div class="navbar navbar-inverse navbar-fixed-top">
        <div class="container">
            <div class="navbar-header">
                <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                </button>

                @Html.ActionLink("Clear Path Direct", "Index", "Home", new { area = "" }, new { @class = "navbar-brand" })
            </div>
            <div class="navbar-collapse collapse">
               @if (User.IsInRole("Admin"))
               {
                <ul class="nav navbar-nav">
                    <li class="dropdown">
                        <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button"
                           aria-haspopup="true" aria-expanded="false">Tools<span class="caret"></span></a>
                        <ul class="dropdown-menu">
                            <li class="text-center">@Html.ActionLink("Media Jobs", "Index", "MediaJobs")</li>
                            <li class="text-center">Order Processing</li>
                            <li class="text-center">Media Reporting</li>
                        </ul>
                    </li>
                    <li class="dropdown">
                        <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button"
                           aria-haspopup="true" aria-expanded="false">Manage<span class="caret"></span></a>
                        <ul class="dropdown-menu">
                            <li class="text-center">@Html.ActionLink("Manage Clients", "Index", "Clients")</li>
                            <li class="text-center">@Html.ActionLink("Manage Media Companies", "Index", "MediaCompanies")</li>
                            <li class="text-center">@Html.ActionLink("Manage Websites", "Index", "Websites")</li>
                        </ul>
                    </li>

                </ul>
               }
                @Html.Partial("_LoginPartial")

            </div>
        </div>
    </div>
                }
    <div class="container body-content">
        @RenderBody()
        <!--
        <footer>
            <p>&copy; @DateTime.Now.Year - CPD Management Tool</p>
        </footer>
            -->
    </div>

    @Scripts.Render("~/bundles/jquery")
    @Scripts.Render("~/bundles/bootstrap")
    <!--angular scripts-->
    @Scripts.Render("~/bundles/Angular")
    <!-- ---->
    @RenderSection("scripts", required: false)
</body>
</html>

where I am bring in sources

为什么我的应用程序在我的控制器运行时运行:

angular.module('app', ['ui.bootstrap']).controller('JobCtrl',
        [
            'JobService',
            'WebsiteService',
            'MediaCompanyService',
            'ProductService',
            '$scope',
            '$uibModal',
            'PageAlertService',
            function (JobService, WebsiteService, MediaCompanyService,
                ProductService, $scope, $uibModal,PageAlertService)

当我拥有它时打破:

angular.module('app').controller('JobCtrl',
    [
        'JobService',
        'WebsiteService',
        'MediaCompanyService',
        'ProductService',
        '$scope',
        '$uibModal',
        'PageAlertService',
        function (JobService, WebsiteService, MediaCompanyService,
            ProductService, $scope, $uibModal,PageAlertService)

非常感谢帮助!

1 个答案:

答案 0 :(得分:0)

我遇到的问题是我在app模块(app.js)中导入了所有控制器和服务。谢谢@Claies向我指出这一点。

错误:

      angular.module('app',
    [
        'JobCtrl',
        'JobSvc',
        'WebsiteCtrl',
        'WebsiteSvc',
        'myClientCtrl',
        'ClientSvc',
        'MediaCompanyCtrl',
        'MediaCompanySvc',
        'PageAlertSvc',
        'ui.bootstrap',
        'Common'
    ]
);

从右:

angular.module('app', ['ui.bootstrap']);