简体   繁体   中英

Why my Angular JS app is not working?

Here is 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

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

When I load the page I don't get "I am 10" rather it's blank page. But when I open the source code using Ctrl+U I can see "<p>I am {{ 4+6 }}</p>"

在此处输入图片说明

I am using XAMMP to access my files.

You're using the self-closing script tag which will not work. 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.

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 . This prevents your module from being loaded hence your angular app is not working.

use

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

All the best!!!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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