我想使用带角度的require,我创建了一个示例应用程序用于学习。我的代码文件看起来像这样
的index.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>RequireJs Demo</title>
<script src="require.js" data-main="main.js"></script>
</head>
<body ng-controller="myController">
{{message}}
</body>
</html>
&#13;
main.js
require.config({
paths: {
angular: 'angular.min',
angularresourse:'angular-resource.min'
},
shim: {
angularresourse:['angular'],
"angular": {
exports: "angular"
}
}
});
require(['angular', 'module'],
function () {
angular.bootstrap(document, ['app']);
}
);
&#13;
module.js
define(['angular', 'controller'], function (angular,controller) {
angular.module('app',[])
.controller('myController', controller);
});
&#13;
controller.js
define([], function () {
var myController = function ($scope) {
$scope.message = "RequireJs Integrated successfully";
};
myController.$inject = ['$scope'];
return myController;
});
&#13;
但执行此操作时显示错误为
&#34; angular.min.js:6未捕捉错误:[$ injector:modulerr] http://errors.angularjs.org/1.5.8/ $注射器/ modulerr P0 =应用&安培; P1 =错误%3A%20%... TTP%3A%2F%2Flocalhost%3A8383%2FAngular_Require%2Fangular.min.js%3A20%3A390)&#34; < / p>
请有人帮帮我...
答案 0 :(得分:0)
在HTML中使用像这样的ng-app="app"
<html lang="en" ng-app="app">
<head>
<meta charset="UTF-8">
<title>RequireJs Demo</title>
<script src="require.js" data-main="main.js"></script>
</head>
<body ng-controller="myController">
{{message}}
</body>
</html>
在代码中添加JS文件。