angularjs - angularjs 模块不可用,即使我有它
问题描述
我正在学习 AngularJS 并遇到问题。这是我的文件结构,
project
|-index.html
|-todoitems.html
|-lib
|-script.js
|-directives.js
<!-- index.html -->
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="lib/style.css" />
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.1/dist/css/bootstrap.min.css"
rel="stylesheet"
integrity="sha384-+0n0xVW2eSR5OomGNYDnhzAbDsOXxcvSN1TPprVMTNDbiYZCxYbOOl7+AMvyTG2x"
crossorigin="anonymous"
/>
<script src="lib/script.js"></script>
<script src="lib/directives.js"></script>
</head>
<body ng-app="todo" ng-cloak>
<div ng-controller="TodoCtrl">
<div class="container">
<h1>Hello {{name}}</h1>
<todo-items></todo-items>
</div>
</div>
</body>
</html>
// script.js
import angular from 'angular';
var app = angular.module('todo', []);
app.controller('TodoCtrl', ['$scope', function($scope){
$scope.name = 'World'
}])
// directives.js
import angular from 'angular';
var app = angular.module('todo', []);
app.directive('todoItems', [
function(){
return {
template: '<h3> hello</h3>'
}
}
])
但是我收到了这个错误,
Error: [$injector:nomod] Module 'todo' is not available! You either misspelled the module name or forgot to load it. If registering a module ensure that you specify the dependencies as the second argument.
有什么我错过或做错了吗?
解决方案
推荐阅读
- kubernetes - 具有与 Active Directory 集成的 Web gui 的 Kubernetes
- routes - 默认路线计算器是使用最短时间还是最短距离?
- ruby-on-rails - 修改 rails mongoid 查询中的值
- apache-kafka - 消费者没有收到订阅后创建的主题的消息
- python - 由于 SSL 错误,无法使用 pip 安装 python 库
- java - 如何使用 Java 从 JSON 文件中获取密钥计数?
- r - 如何在测试中设置最大失败次数?
- javascript - 带有重音符号的正则表达式搜索结果突出显示
- reactjs - mini-css-extract-plugin:仅在导入 JS 文件时导入 CSS 文件
- r - 与原始栅格相比,tmap 正在为裁剪的栅格图层绘制不同的图例(值范围?)