简体   繁体   English

使用Angular.js时出错

[英]Error using Angular.js

I've been doing an Angular.js course, and now that I finished it, I wanted to give it a try and do some tests. 我一直在做Angular.js课程,现在我完成了它,我想尝试一下并做一些测试。

I used the basic html file for beginning: 我使用基本的html文件作为开始:

<html ng-app="app.js">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <script src="plugins/angular-min-1.4.3.js"></script>
  </head>
  <body>
  </body>
</html>

... which points to the simple angular app.js main module declaration: ...指向简单的有角度的app.js主模块声明:

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

Nothing strange here, no? 这里没什么奇怪的,不是吗? I tried making a few directives and so, but nothing worked. 我尝试做出一些指令,所以,但是没有任何效果。 Then, I found this error, which appears as soon as I only have the above code. 然后,我发现此错误,只有我上面的代码会立即出现。 I guess it's not adding well the plugin or I'm not declaring well the app variable. 我想插件添加得不好,或者我没有很好地声明app变量。

12:32:44.547 Error: [$injector:modulerr] http://errors.angularjs.org/1.4.3/ $injector/modulerr?p0=app.js&p1=%5B%24injector%3Anomod%5D%20http%3A%2F%2Ferrors.angularjs.org%2F1.4.3%2F%24injector%2Fnomod%3Fp0%3Dapp.js%0AJ%2F%3C%40http%3A%2F%2Flocalhost%2FAngularPruebas%2Fplugins%2Fangular-min-1.4.3.js%3A6%3A416%0Ade%2F%3C%2F%3C%2F%3C%40http%3A%2F%2Flocalhost%2FAngularPruebas%2Fplugins%2Fangular-min-1.4.3.js%3A24%3A66%0Aa%40http%3A%2F%2Flocalhost%2FAngularPruebas%2Fplugins%2Fangular-min-1.4.3.js%3A23%3A109%0Ade%2F%3C%2F%3C%40http%3A%2F%2Flocalhost%2FAngularPruebas%2Fplugins%2Fangular-min-1.4.3.js%3A23%3A1%0Ag%2F%3C%40http%3A%2F%2Flocalhost%2FAngularPruebas%2Fplugins%2Fangular-min-1.4.3.js%3A37%3A381%0Am%40http%3A%2F%2Flocalhost%2FAngularPruebas%2Fplugins%2Fangular-min-1.4.3.js%3A7%3A320%0Ag%40http%3A%2F%2Flocalhost%2FAngularPruebas%2Fplugins%2Fangular-min-1.4.3.js%3A37%3A229%0Aeb%40http%3A%2F%2Flocalhost%2FAngularPruebas%2Fplugins%2Fangular-min-1.4.3.js%3A40%3A1%0AAc%2Fd%40http%3A%2F%2Floca 12:32:44.547错误:[$ injector:modulerr] http://errors.angularjs.org/1.4.3/ $ injector / modulerr?p0 = app.js&p1 =%5B%24injector%3Anomod%5D%20http%3A %2F%2Ferrors.angularjs.org%2F1.4.3%2F%24injector%2Fnomod%3Fp0%3Dapp.js%0AJ%2F%3C%40http%3A%2F%2Flocalhost%2FAngularPruebas%2Fplugins%2Fangular分钟-1.4.3的.js%3A6%3A416%0Ade%2F%3C%2F%3C%2F%3C%40http%3A%2F%2Flocalhost%2FAngularPruebas%2Fplugins%2Fangular分钟-1.4.3.js%3A24 3A66%%%0AA 40http %3A%2F%2Flocalhost%2FAngularPruebas%2Fplugins%2Fangular分钟-1.4.3.js%3A23%3A109%0Ade%2F%3C%2F%3C%40http%3A%2F%2Flocalhost%2FAngularPruebas%2Fplugins%2Fangular分钟-1.4.3.js%3A23%3A1%0Ag%2F%3C%40http%3A%2F%2Flocalhost%2FAngularPruebas%2Fplugins%2Fangular分钟-1.4.3.js%3A37%3A381%上午12点%40http%3A%2F %2Flocalhost%2FAngularPruebas%2Fplugins%2Fangular分钟-1.4.3.js%3A7%3A320%0Ag%40http%3A%2F%2Flocalhost%2FAngularPruebas%2Fplugins%2Fangular分钟-1.4.3.js%3A37%3A229%0Aeb %40http%3A%2F%2Flocalhost%2FAngularPruebas%2Fplugins%2Fangular分钟-1.4.3.js%3A40%3A1%0AAc%2FD%40http%3A%2F%2Floca lhost%2FAngularPruebas%2Fplugins%2Fangular-min-1.4.3.js%3A19%3A339%0AAc%40http%3A%2F%2Flocalhost%2FAngularPruebas%2Fplugins%2Fangular-min-1.4.3.js%3A20%3A151%0AZd%40http%3A%2F%2Flocalhost%2FAngularPruebas%2Fplugins%2Fangular-min-1.4.3.js%3A18%3A464%0A%40http%3A%2F%2Flocalhost%2FAngularPruebas%2Fplugins%2Fangular-min-1.4.3.js%3A289%3A428%0Aa%40http%3A%2F%2Flocalhost%2FAngularPruebas%2Fplugins%2Fangular-min-1.4.3.js%3A176%3A73%0AGf%2Fc%40http%3A%2F%2Flocalhost%2FAngularPruebas%2Fplugins%2Fangular-min-1.4.3.js%3A35%3A212%0A1 angular-min-1.4.3.js:6:415 lhost%2FAngularPruebas%2Fplugins%2Fangular分钟-1.4.3.js%3A19%3A339%0AAc%40http%3A%2F%2Flocalhost%2FAngularPruebas%2Fplugins%2Fangular分钟-1.4.3.js%3A20%3A151%0AZd% 40http%3A%2F%2Flocalhost%2FAngularPruebas%2Fplugins%2Fangular分钟-1.4.3.js%3A18%3A464%0A%40http%3A%2F%2Flocalhost%2FAngularPruebas%2Fplugins%2Fangular分钟-1.4.3.js% 3A289%3A428%0AA%40http%3A%2F%2Flocalhost%2FAngularPruebas%2Fplugins%2Fangular分钟-1.4.3.js%3A176%3A73%0AGf%2FC%40http%3A%2F%2Flocalhost%2FAngularPruebas%2Fplugins%2Fangular- min-1.4.3.js%3A35%3A212%0A1 angular-min-1.4.3.js:6:415

Why does this happen? 为什么会这样?

You have an error in html. 您在html中有错误。
Your app is app , not app.js . 您的应用程序是app ,而不是app.js。

<html ng-app="app">
  <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
        <script src="plugins/angular-min-1.4.3.js"></script>
  </head>
  <body></body>
</html>

Ok, I was being really silly not adding the app.js file. 好的,我真的很傻,没有添加app.js文件。 Now that I added it, ng-app="app" finds it properly. 现在,我添加了它,ng-app =“ app”可以正确找到它。

On ng-app, you must say the name of the app, in this case it's "app" and not the file. 在ng-app上,您必须说出应用程序的名称,在这种情况下,它是“ app”而不是文件。 I recommend you also not using ng-app on the HTML tag. 我建议您也不要在HTML标签上使用ng-app。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM