AngularJS处的未捕获对象+;RequireJS+;多姆雷迪
我有一个正常工作的AngularJS应用程序,并开始使用RequireJS作为模块依赖项。遵循本指南--使用domReady插件手动引导angular应用程序 在Chrome中测试,并在控制台中获得未捕获对象。没有angular通常提供的常规细节,只有无用的调用堆栈 下面是我的应用程序的一个非常简化的版本:AngularJS处的未捕获对象+;RequireJS+;多姆雷迪,angularjs,requirejs,domready,angular-bootstrap,Angularjs,Requirejs,Domready,Angular Bootstrap,我有一个正常工作的AngularJS应用程序,并开始使用RequireJS作为模块依赖项。遵循本指南--使用domReady插件手动引导angular应用程序 在Chrome中测试,并在控制台中获得未捕获对象。没有angular通常提供的常规细节,只有无用的调用堆栈 下面是我的应用程序的一个非常简化的版本: <html ng-app="myApp"> <body> <script data-main="/scripts/config.js" src="scr
<html ng-app="myApp">
<body>
<script data-main="/scripts/config.js" src="scripts/require.js"></script>
</body>
</html>
app.js:
define(['angular'], function (angular) {
var app = angular.module("myApp", []);
return app;
});
实际上,在简化版本中,错误更容易发现。问题在于模块的双重使用。第一次使用HTML(从RequireJS之前的时间遗留下来): 因此,这是HTML的正确版本:
<html> <!-- Notice: removed ng-app -->
<body>
<script data-main="/scripts/config.js" src="scripts/require.js"></script>
</body>
</html>
<html ng-app="myApp">
angular.bootstrap(document, ['myApp']);
<html> <!-- Notice: removed ng-app -->
<body>
<script data-main="/scripts/config.js" src="scripts/require.js"></script>
</body>
</html>
require(['domReady!'], function (document) {
try {
// Wrap this call to try/catch
angular.bootstrap(document, ['materialApp']);
}
catch (e) {
console.error(e.stack || e.message || e);
}
});