Uncaught Error - 我的angularjs Web应用程序中的Injector modulerr

时间:2016-03-04 07:14:41

标签: angularjs

我尝试做一个图表演示。我得到了未被捕获的模块化。我无法解决这个问题。请让我知道我错在哪里。

注意:

我已经运行了bower install,并且已将库注入/ public / lib文件夹下的模块。

我的index.jade

doctype html
html(lang='en', xmlns='http://www.w3.org/1999/xhtml', xmlns:fb='https://www.facebook.com/2008/fbml', itemscope='itemscope', itemtype='http://schema.org/Product')
head
    block header    
        block stylesheet
            link(rel='stylesheet', href='/semantic/semantic.min.css')
            link(rel='stylesheet', href='/css/vendor.min.css')
        block headerscript
            script(type='text/javascript', src="//ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js")
            script(type='text/javascript', src='//ajax.googleapis.com/ajax/libs/angularjs/1.3.15/angular.min.js')
            script(type='text/javascript', src='//cdnjs.cloudflare.com/ajax/libs/angular.js/1.2.20/angular-route.min.js')
body(ng-init="compare='hellovar'")
    .ui.grid
        .ui.computer.tablet.only.fitted.row
            .column
                .ui.menu
                    .item
                        a.ui.green.button(href="/")
                            | Chart Demo
        .ui.mobile.only.three.column.inverted.black.fitted.row
            .column.floated.left.inverted
                .ui.menu.fluid.two.item.inverted
                    header.item
                        a.ui.green.icon.button(href="/")
                            i.content.icon
            .column
                | Alasql Demo
            .column.right.aligned
        .fitted.row
            .column
                block content
    div(ui-view)
block footer
    script(type='text/javascript').
        angular.element(document).ready(function() {
            angular.bootstrap(document, ['home.core']);
        });

我的控制器部分

'use strict';  
angular.module('home.core',['ngRoute']);

angular.module('home.core')
    .controller('home.core.controller', ['$rootScope', '$scope', '$window', 
        function($rootScope, $scope, $window) {
            console.log("inside home core controller");
            function _init() {
               console.log("Inside Home Controller");
            }           
            _init();
        }
    ]);

angular.module('home.core')
    .config(
        ["$stateProvider", "$urlRouterProvider",
            function ($stateProvider, $urlRouterProvider) {
                $stateProvider
                .state("home-core", {
                        url: '/',
                        templateUrl: 'partials/home/core/index.html',
                        controller : 'home.core.controller'                       
                    });                
            }
        ]);
angular.module('home.core')
    .factory('home.core.service', ['Restangular',
        function(Restangular) {
            var restAngular = Restangular.withConfig(function(Configurer) {
                Configurer.setBaseUrl('/api/ecommerce');
            });

            return {
                create: restAngular.all('')
                    .post
            }
        }
    ]);

运行网络应用时出现以下错误

未捕获错误:[$ injector:modulerr] http://errors.angularjs.org/1.3.15/ $ injector / modulerr?p0 = home.core& p1 = Error ... gleapis.com%2Fajax%2Flibs%2Fangularjs%2F1.3.15%2Fangular.min。 JS%3A17%3A381

1 个答案:

答案 0 :(得分:1)

首先,我看不到您在运行restangular脚本的位置:

<script src="js/lib/restangular.min.js"></script>

其次,你的所有Angular代码都在一个文件中吗?首先必须将restangular注入主模块。您可以尝试将代码更改为:

'use strict';  
angular.module('home.core',['ngRoute','restangular'])

.controller('home.core.controller', ['$rootScope', '$scope', '$window', 
    function($rootScope, $scope, $window) {
        console.log("inside home core controller");
        function _init() {
           console.log("Inside Home Controller");
        }           
        _init();
    }
])

.config(
    ['$stateProvider', '$urlRouterProvider',
        function ($stateProvider, $urlRouterProvider) {
            $stateProvider
            .state("home-core", {
                    url: '/',
                    templateUrl: 'partials/home/core/index.html',
                    controller : 'home.core.controller'                       
                });                
        }
    ])

.factory('home.core.service', ['Restangular',
    function(Restangular) {
        var restAngular = Restangular.withConfig(function(Configurer) {
            Configurer.setBaseUrl('/api/ecommerce');
        });

        return {
            create: restAngular.all('')
                .post
        }
    }
])