我正在尝试用AngularJs连接Angular 2。谁会知道为什么加载外部js失败的原因,内联正常工作。
app.module.ts:
platformBrowserDynamic().bootstrapModule(AppModule).then(platform => {
console.log('Bootstrapping in Hybrid mode with Andular & AngularJs');
const upgrade = platform.injector.get(UpgradeModule) as UpgradeModule;
upgrade.bootstrap(document.body, ['ToDo']);
})
AngularJs文件: 这有效:
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.2/angular.min.js"></script>
<script>
angular.module('ToDo', [])
.controller('todoController', ['$scope', function ($scope) {
$scope.todos = [
{ 'title': 'Build a todo app', 'done': false }
]
$scope.addTodo = function () {
$scope.todos.push({ 'title': 'Build a todo app', 'done': false });
}
$scope.clearCompleted = function () { }
}])
</script>
这失败,并显示错误:
zone.js:682未处理的承诺拒绝:[$ injector:modulerr] http://errors.angularjs.org/1.6.2/ $ injector / modulerr?...;区:
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.2/angular.min.js"></script>
<script src="index.js"></script>
</script>
'index.js'与内部脚本的内容匹配