简体   繁体   中英

Angular js binding does not work

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Bootstrap 101 Template</title>

<!-- Bootstrap -->
<link href="css/bootstrap.min.css" rel="stylesheet">
<link rel="stylesheet" type="text/css" href="css/style.css">
<!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
<!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
<!--[if lt IE 9]>
  <script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
  <script src="https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script>
<![endif]-->

<!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
<script src="js/jquery.min.js"></script>
<!-- Include all compiled plugins (below), or include individual files as needed -->
<script type="text/javascript" src = "js/angular.min.js"></script>
<script type="text/javascript" src = "js/angular-route.js"></script>
<script type="text/javascript" src = "js/angular-resource.min.js"></script>
<script type="text/javascript" src = "js/script.js"></script>

</head>

<body ng-app>
<div>
{{Hello World!}}
</div>

<script src="js/bootstrap.min.js"></script>
</body>
</html>

script.js

if(typeof angular == 'undefined' )
{
alert("not working");
}
else
{
alert("good");
}

I get alerted good, although the page still has

{{Hello World!}}

What am I missing here? I thought the binding was supposed to work by itself. I am using angular js 1.2.16 btw

//extra characters because stackoverflow wouldn't let me post the question. Says too much code.

All included scripts are good. However you are not telling angular where to start bootstraping your angular application.

You are missing ng-app directive on the html tag.

<html ng-app>

Also the Hello World should be a string.

{{"Hello World!"}}

Working example :

script.js

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

index.html page:

<!DOCTYPE html>
<html ng-app="MyTestApp">
<head>

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