javascript 角度js不起作用
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/17923859/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Angular js does not work
提问by Spring
This is my html file. The angular.js file is under java/main/webapp/js folder and Intellij can see it when I click on it, yet the code does not work! I get a print on screen {{helloMessage}} and not "hello world"
这是我的 html 文件。angular.js 文件在 java/main/webapp/js 文件夹下,点击 Intellij 可以看到,但代码不起作用!我在屏幕上打印 {{helloMessage}} 而不是“hello world”
What am I missing here?
我在这里错过了什么?
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Angular test </title>
</head>
<body>
<h1 ng-controller="HelloWorldCtrl">{{helloMessage}}</h1>
Angular test
<script src="js/angular.js"> </script>
<script type="text/javascript">
function HelloWorldCtrl($scope){
$scope.helloMessage="Hello World";
}
</script >
</body>
</html>
回答by Cherniv
You forgot ng-app
, put it in the body
tag:
你忘了ng-app
,把它放在body
标签中:
<body ng-app>
Have a look at working example.
看看工作示例。