Angular js绑定不起作用

时间:2014-05-31 10:40:19

标签: javascript angularjs

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

虽然页面仍有

,但我收到了警报
{{Hello World!}}

我在这里缺少什么?我认为绑定本身应该起作用。 我使用角度js 1.2.16 btw

//额外的字符,因为stackoverflow不允许我发布问题。说的代码太多了。

2 个答案:

答案 0 :(得分:1)

所有包含的脚本都很好。但是,你并没有告诉角度从哪里开始引导角度应用程序。

您在html标记上缺少ng-app指令。

<html ng-app>

Hello World也应该是一个字符串。

{{"Hello World!"}}

答案 1 :(得分:0)

工作示例:

<强>的script.js

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

index.html页面:

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