【发布时间】:2016-12-24 15:01:12
【问题描述】:
我正在尝试使用 require.js 加载各种角度模块的依赖项。在 dependencies.js 文件中配置依赖项后,我在加载应用程序时遇到错误,提示 “模块不可用”。我尝试了下面给出的文件的 2 种变体,但应用程序在这两个实例上都失败了:
变体 1 - Dependencies.js
require.config({
paths: {
angular: '../lib/dependencies/bower_components/angular/angular',
angularRoute: '../lib/dependencies/bower_components/angular-route/angular-route',
angularMessages: '../lib/dependencies/bower_components/angular-messages/angular-messages',
lodash: "../lib/dependencies/bower_components/lodash/dist/lodash",
jQuery: "../script/datetimepicker/jquery.min", // needed only by the date time picker
datetimepicker: '../script/datetimepicker/jquery.datetimepicker',
underscore: '../lib/dependencies/bower_components/underscore/underscore',
frontendServices: 'frontend-services',
myApp: "test-app"
},
shim: {
jQuery: {
exports: "jQuery"
},
angular: {
exports: "angular"
},
angularRoute: {
exports: "ngRoute"
},
angularRoute: {
deps: ['angular']
},
underscore: {
exports: "_"
},
underscore: {
deps: ['jQuery']
},
datetimepicker: {
deps: ['jQuery']
},
angularMessages: {
deps: ['angular']
},
frontendServices: {
deps: ['angular', 'lodash']
},
myApp: {
deps: [ 'lodash', 'angular', 'angularMessages', 'frontendServices', 'underscore']
}
}
});
require(['myApp'], function () {
angular.bootstrap(document.getElementById('myApp'), ['myApp']);
});
变体 2 - Dependencies.js
require.config({
paths: {
angular: '../lib/dependencies/bower_components/angular/angular',
angularRoute: '../lib/dependencies/bower_components/angular-route/angular-route',
angularMessages: '../lib/dependencies/bower_components/angular-messages/angular-messages',
lodash: "../lib/dependencies/bower_components/lodash/dist/lodash",
jQuery: "../script/datetimepicker/jquery.min", // needed only by the date time picker
datetimepicker: '../script/datetimepicker/jquery.datetimepicker',
underscore: '../lib/dependencies/bower_components/underscore/underscore',
frontendServices: 'frontend-services',
myApp: "test-app"
},
shim: {
jQuery: {
exports: "jQuery"
},
angular: {
exports: "angular"
},
angularRoute: {
exports: "ngRoute"
},
angularRoute: {
deps: ['angular']
},
underscore: {
deps: ['jQuery']
},
datetimepicker: {
deps: ['jQuery']
},
angularMessages: {
deps: ['angular']
},
frontendServices: {
deps: ['angular', 'lodash']
},
myApp: {
deps: [ 'lodash', 'angular', 'angularMessages', 'frontendServices', 'underscore']
}
}});
require(['myApp'], function () {
angular.bootstrap(document.getElementById('myApp'), ['myApp']);
});
我的控制器文件:
angular.module('myApp', [ 'frontendServices', 'underscore', 'angularRoute']).controller(
'TableCtrl',
[ '$http',
'$scope',
function($scope, $timeout) {
// contents
} ]);
加载应用程序后,我收到如下错误:
错误:[$injector:nomod] 模块“下划线”不可用!您要么拼错了模块名称,要么忘记加载它。如果注册模块,请确保将依赖项指定为第二个参数。 http://errors.angularjs.org/1.3.8/$injector/nomod?p0=下划线
谁能帮我提供使用 require.js 配置下划线和 ngRoute 的正确方法????
【问题讨论】:
标签: javascript jquery angularjs requirejs underscore.js