我开始使用RequireJS
,依赖加载很好,但在回调方法中所有依赖都是undefined
。
require.config({
baseUrl: 'js',
paths: {
angular: '../lib/angular/angular',
myApp: 'app',
states: 'app-states',
controllers: 'controllers',
filters: 'filters',
services: 'services',
oauth2: 'oauth2'
//async: 'lib/require/async'
},
shim: {
'myApp': {
deps: ['angular']
},
'states' : {
deps: ['angular', 'myApp']
},
'controllers': {
deps: ['angular', 'myApp']
},
'filters': {
deps: ['angular', 'myApp']
},
'services': {
deps: ['angular', 'myApp']
}
}
});
require(['angular', 'myApp', 'states', 'controllers', 'filters', 'services'], function(angular, myApp, states, controllers, filters, services) {
'use strict';
console.log('requireJs done');
console.log(angular);
console.log(myApp);
angular.bootstrap(document, ['myapp']);
});
如果我只是 require angular
,则不会调用回调方法。我想知道为什么。
require(['angular', function(angular) {
console.log("requireJS done");
}]);