gpt4 book ai didi

angularjs - 从另一个脚本文件加载时, Angular 模块的 $injector err

转载 作者:行者123 更新时间:2023-12-03 08:18:19 27 4
gpt4 key购买 nike

我是 Angular 的新手,我正在学习某些教程,但遇到了以下错误,请帮我修复它。我有 2 个文件,index.html 和 script.js,当我加载 script.js 文件时,它给了我 2 个错误:1.angular is not defined 2.Uncaught Error: [$injector:modulerr]
附上我的代码:

var app = angular.module('app', []);

app.controller('todoController', ['$scope', function($scope) {
$scope.list = [{
name: "Testing",
completed: true
},
{
name: "test1",
completed: false
},
{
name: "app wasn't working",
completed: true
},
{
name: 'testing 2',
completed: true
}
]
}])
<!DOCTYPE html>
<html ng-app="app">

<head>
<script src="script.js"></script>
</head>

<body>
<div ng-controller="todoController">
<ul style="list-style-type: none;">
<li ng-repeat="todo in list">
<input type="checkbox" ng-model="todo.completed"> {{todo.name}}
</li>
</ul>
</div>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.9/angular.min.js"></script>
</body>

</html>


当我尝试在浏览器上运行上述代码片段时,出现以下 2 个错误:

1.

Uncaught ReferenceError: angular is not defined



2.

Uncaught Error: [$injector:modulerr] angular.js:88 Uncaught Error: [$injector:modulerr] http://errors.angularjs.org/1.6.9/$injector/modulerr?p0=app&p1=Error%3A%20%5B%24injector%3Anomod%5D%20http%3A%2F%2Ferrors.angularjs.org%2F1.6.9%2F%24injector%2Fnomod%3Fp0%3Dapp%0A%20%20%20%20at%20https%3A%2F%2Fajax.googleapis.com%2Fajax%2Flibs%2Fangularjs%2F1.6.9%2Fangular.min.js%3A7%3A76%0A%20%20%20%20at%20https%3A%2F%2Fajax.googleapis.com%2Fajax%2Flibs%2Fangularjs%2F1.6.9%2Fangular.min.js%3A26%3A408%0A%20%20%20%20at%20b%20(https%3A%2F%2Fajax.googleapis.com%2Fajax%2Flibs%2Fangularjs%2F1.6.9%2Fangular.min.js%3A25%3A439)%0A%20%20%20%20at%20https%3A%2F%2Fajax.googleapis.com%2Fajax%2Flibs%2Fangularjs%2F1.6.9%2Fangular.min.js%3A26%3A182%0A%20%20%20%20at%20https%3A%2F%2Fajax.googleapis.com%2Fajax%2Flibs%2Fangularjs%2F1.6.9%2Fangular.min.js%3A42%3A332%0A%20%20%20%20at%20r%20(https%3A%2F%2Fajax.googleapis.com%2Fajax%2Flibs%2Fangularjs%2F1.6.9%2Fangular.min.js%3A8%3A7)%0A%20%20%20%20at%20g%20(https%3A%2F%2Fajax.googleapis.com%2Fajax%2Flibs%2Fangularjs%2F1.6.9%2Fangular.min.js%3A42%3A180)%0A%20%20%20%20at%20gb%20(https%3A%2F%2Fajax.googleapis.com%2Fajax%2Flibs%2Fangularjs%2F1.6.9%2Fangular.min.js%3A46%3A250)%0A%20%20%20%20at%20c%20(https%3A%2F%2Fajax.googleapis.com%2Fajax%2Flibs%2Fangularjs%2F1.6.9%2Fangular.min.js%3A22%3A19)%0A%20%20%20%20at%20Uc%20(https%3A%2F%2Fajax.googleapis.com%2Fajax%2Flibs%2Fangularjs%2F1.6.9%2Fangular.min.js%3A22%3A332)

最佳答案

您需要加载 script.js 之后 angular.js 引用已加载。将您的订单更改为以下。

<!DOCTYPE html>
<html ng-app="app">

<head>
</head>

<body>
<div ng-controller="todoController">
<ul style="list-style-type: none;">
<li ng-repeat="todo in list">
<input type="checkbox" ng-model="todo.completed"> {{todo.name}}
</li>
</ul>
</div>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.9/angular.min.js">
</script>
<script src="script.js"></script>
</body>
</html>

关于angularjs - 从另一个脚本文件加载时, Angular 模块的 $injector err,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49744402/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com