简体   繁体   English

为什么我的Angular JS应用无法正常工作?

[英]Why my Angular JS app is not working?

Here is firstAngularJSApp.html 这是firstAngularJSApp.html

<html ng-app="store"><!-- "ng-app" creates and angular app by running the module. because of ng-app html inside of this tag will be treated as part of angular app --> 
<head>
    <link rel="stylesheet" type="text/css" href="bootstrap.min.css"/>
    <script type="text/javascript" src="angular.min.js"></script>
    <script type="text/javascript" src="app.js"/>
</head>
<body>

<p>I am {{ 4+6 }}</p>

</body>
</html>

Here is app.js 这是app.js

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

When I load the page I don't get "I am 10" rather it's blank page. 当我加载页面时,我没有得到“我是10”,而是空白页面。 But when I open the source code using Ctrl+U I can see "<p>I am {{ 4+6 }}</p>" 但是,当我使用Ctrl+U打开源代码时,我可以看到"<p>I am {{ 4+6 }}</p>"

在此处输入图片说明

I am using XAMMP to access my files. 我正在使用XAMMP访问我的文件。

You're using the self-closing script tag which will not work. 您正在使用无法自动关闭的script标签。 See Why don't self-closing script tags work? 请参阅为什么自关闭脚本标记不起作用?

So, your app.js file is not included on the page and your angular app is not bootstrapped. 因此,您的app.js文件不包含在页面上,并且您的angular应用程序也未引导。

Use 采用

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

Also, make sure the file paths are correct. 另外,请确保文件路径正确。

seems like your angular framework is not loaded to the page. 似乎您的角度框架未加载到页面。 make sure it is loaded correctly and check the paths. 确保已正确加载它并检查路径。 if you want you can use the network tab in developer tools to check that. 如果需要,可以使用开发人员工具中的“网络”标签进行检查。

Your app.js will not load by this method of self closing tags because it is usually intended to contain some piece of code inside it . 您的app.js不会通过这种自动关闭标签的方法加载,因为它通常旨在在其中包含一些代码 This prevents your module from being loaded hence your angular app is not working. 可以防止模块被加载,因此您的角度应用程序无法正常工作。

use 采用

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

All the best!!! 祝一切顺利!!!

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

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