关于 angular 指令的错误

Error regarding angular directives

这就是我得到的(无法实例化模块存储,原因是: 错误:[$injector:nomod] http://errors.angularjs.org/1.3.9/$injector/nomod?p0=store)

(一个更具描述性的错误)

模块 'store' 不可用!您要么拼错了模块名称,要么忘记加载它。如果注册模块,请确保将依赖项指定为第二个参数。

我做的一切都是正确的 我在 app.js 文件之前加载了 angular.js 文件,我一直在搜索同样的问题,但仍然找不到主要问题。

index.html

<!DOCTYPE html>
<html>
<head ng-app='store'>

<!-- CSS -->
<link rel="stylesheet" type="text/css" href="bootstrap.min.css">
<!-- ANGULAR FILES -->

<script type="text/javascript" src="angular.min.js"></script>
<script type="text/javascript" src="app.js"></script>

</head> 
<body class="container" ng-controller="mainController as control">


<p>{{ control.message }}</p>
</body>
</html>

app.js

angular.module('store', []);
.controller('mainController', function() {

    var vm = this;

    vm.message = "awesome";


});

即使是像这样的简单表达 {{ 1 + 6 }} 不起作用

您正在将 ng-app 指令放置在 head 上并试图在主体上加载控制器。因此,您的应用程序根元素成为文档的 head 并且它不适用于您尝试加载控制器的正文。而是将其移动到您加载 angular 实体的应用程序的根目录。例如将它放在 htmlbody 上:-

<html ng-app="store">

documentation

Use this directive to auto-bootstrap an AngularJS application. The ngApp directive designates the root element of the application and is typically placed near the root element of the page - e.g. on the or tags.

同时纠正你的语法错误@angular.module('store', []);.controller(

您正在使用 ; 终止应用程序声明并尝试将其链接起来。

演示

angular.module('store', []).controller('mainController', function() {

  var vm = this;

  vm.message = "awesome";


});
<!DOCTYPE html>
<html ng-app='store'>

<head>

  <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>

</head>

<body class="container" ng-controller="mainController as control">


  <p>{{ control.message }}</p>
</body>

</html>