简体   繁体   English

使用RequireJS将外部Angle模块加载到'mainApp'模块时出现问题

[英]Issue while loading external angular module to 'mainApp' module using RequireJS

I recently started using RequireJS with AngularJS. 我最近开始在AngularJS中使用RequireJS。 I came across a plugin called AngularAMD, which makes it easier for Require and Angular to work together. 我遇到了一个名为AngularAMD的插件,它使Require和Angular一起工作变得更加容易。 I have the following config. 我有以下配置。

require.config({
    baseUrl: "",    
    paths: {
        'angular': 'lib/js/angular.min',
        'angular-route': 'lib/js/angular-route.min',
        'angular-resource': 'lib/js/angular-resource.min',
        'angularAMD': 'lib/js/angularAMD.min',
        'jquery':'lib/js/jquery-1.11.3.min',
        'bootstrap':'lib/js/bootstrap.min',
        'httpAPIService' : 'httpAPIService',
        'angular-charts':'lib/js/angular-charts',
        'd3': 'lib/js/d3.min'
    },
    shim: { 'bootstrap':['jquery'], 'angular': ['jquery', 'bootstrap'], 'angularAMD': ['angular'], 'angular-route': ['angular'], 'angular-resource': ['angular'], 'angular-charts':['angular', 'd3'], 'httpAPIService': ['mainApp']},
    deps: ['mainApp']
});

Now in mainApp.js I have the following code: 现在在mainApp.js我有以下代码:

define(['angularAMD', 'angular-route'], function (angularAMD) {

    var mainApp = angular.module('mainApp', ['ngRoute']);

    mainApp.config(function ($routeProvider) {
        $routeProvider.when("/userAgreement", angularAMD.route({
            templateUrl: 'modules/agreement/views/eulaView.html', controller: 'eulaController',
            controllerUrl: 'modules/agreement/js/eulaController'
        }))
        .otherwise({
            redirectTo: '/' 
        });
    });
    return angularAMD.bootstrap(mainApp);
});

Which works fine. 哪个工作正常。 But if I try to add angular-charts module to it. 但是,如果我尝试向其中添加angular-charts模块。 Like this: 像这样:

define(['angularAMD', 'angular-route', 'angular-charts'], function (angularAMD) {

    var mainApp = angular.module('mainApp', ['ngRoute', 'angularCharts']);

    mainApp.config(function ($routeProvider) {
        $routeProvider.when("/userAgreement", angularAMD.route({
            templateUrl: 'modules/agreement/views/eulaView.html', controller: 'eulaController',
            controllerUrl: 'modules/agreement/js/eulaController'
        }))
        .otherwise({
            redirectTo: '/' 
        });
    });
    return angularAMD.bootstrap(mainApp);
});

It' gives me $injector:modulerr Module Error . 它给了我$injector:modulerr Module Error I am new to AMD concept. 我是AMD概念的新手。 Please help. 请帮忙。

Have you tried ngload per documentation ? 您是否按文档尝试过ngload

define(['angularAMD', 'angular-route', 'ngload!angular-charts'], function (angularAMD) {

...

})

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM