I recently started using RequireJS with AngularJS. I came across a plugin called AngularAMD, which makes it easier for Require and Angular to work together. 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:
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. 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
. I am new to AMD concept. Please help.
Have you tried ngload
per documentation ?
define(['angularAMD', 'angular-route', 'ngload!angular-charts'], function (angularAMD) {
...
})
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.