我是 requireJS 的新手,我想启动并运行一个简单的“hello worldish”项目。不过我遗漏了一些东西,因为在尝试加载angular is not defined
时我得到了一个 JS 错误。GreetCtrl
索引.html:
<!DOCTYPE html>
<html ng-app="ReqApp" ng-controller="GreetCtrl">
<body>
<h1>{{greeting}}!</h1>
<script src="assets/require/require.js" data-main="assets/require/main"></script>
</body>
</html>
主.js:
require.config({
// alias libraries paths
paths: {
'domReady': 'domReady',
'angular': '../../vendor/angular/angular.min',
'GreetCtrl': '../../src/app/modules/GreetCtrl',
'app': '../../src/app/app'
},
// angular does not support AMD out of the box, put it in a shim
shim: {
'angular': {
exports: 'angular'
}
},
// kick start application
deps: ['./bootstrap']
});
bootstrap.js:
define([
'require',
'angular',
'app'
], function (require, ng) {
'use strict';
require(['domReady!'], function (document) {
ng.bootstrap(document, ['ReqApp']);
});
});
应用程序.js:
define([
'angular',
'GreetCtrl'
], function (ng) {
'use strict';
return ng.module('ReqApp', [
'ReqApp.GreetCtrl'
]);
});
最后是 GreetCtrl.js:
angular.module( 'ReqApp.GreetCtrl', [])
.controller( 'GreetCtrl', function GreetCtrl ($scope) {
$scope.greeting = "greetings puny human";
});
根据萤火虫的说法,第 1 行GreetCtrl.js
会引发angular is not defined
. 我在这里想念什么?
提前致谢!!