【问题标题】:Error regarding angular directives关于角度指令的错误
【发布时间】:2015-03-15 07:14:01
【问题描述】:

这就是我得到的(无法实例化模块存储,原因是: 错误:[$injector:nomod] http://errors.angularjs.org/1.3.9/$injector/nomod?p0=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 }} 不起作用

【问题讨论】:

    标签: angularjs angularjs-directive


    【解决方案1】:

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

    <html ng-app="store">
    

    documentation

    使用该指令自动引导 AngularJS 应用程序。 ngApp 指令指定应用程序的根元素,通常放置在页面的根元素附近 - 例如在 or 标签上。

    同时纠正你的语法错误@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>

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-10-31
      • 1970-01-01
      • 2016-05-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多