aandis
aandis

Reputation: 4212

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.

Upvotes: 1

Views: 261

Answers (2)

msapkal
msapkal

Reputation: 8346

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!"}}

Upvotes: 1

Mehmet
Mehmet

Reputation: 1874

Working example :

script.js

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

index.html page:

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

Upvotes: 0

Related Questions