[英]HTML Page with AngularJS not rendering properly
I am brand new to AngularJS and I'm following an example from a book but am running into issues with the HTML rendering in a simple example. 我是AngularJS的新手,我正在关注一本书的例子,但是我在一个简单的例子中遇到了HTML渲染的问题。
Code is working with no problems in JSFiddle - http://jsfiddle.net/2436t/ 代码在JSFiddle中没有问题 - http://jsfiddle.net/2436t/
I am running this in Firefox 30.0 and I just get the following output and no errors in Firebug 我在Firefox 30.0中运行它,我只是得到以下输出,并在Firebug中没有错误
HTML Code: HTML代码:
<!DOCTYPE html>
<html>
<head>
<title>Hello</title>
<script type="text/javascript" src="angular.min.js"></script>
<script src="controllers.js"></script>
</head>
<body ng-app>
<div ng-controller="HelloController">
<p>{{greeting.text}}</p>
</div>
</body>
</html>
Javascript (in external controllers.js file): Javascript(在外部的controllers.js文件中):
function HelloController($scope)
{
$scope.greeting = {text:"Hello"};
}
I am sure I'm missing something simple but any help would be greatly appreciated, 我相信我错过了一些简单的东西,但任何帮助都会非常感激,
Sean 肖恩
You are missing ng-app="????"
你缺少
ng-app="????"
You also need to inject the controller in the module. 您还需要在模块中注入控制器。
Here is the jsfiddle 这是jsfiddle
http://jsfiddle.net/yogeshgadge/2436t/14/ http://jsfiddle.net/yogeshgadge/2436t/14/
The HTML HTML
<body ng-app="myApp">
<div ng-controller="HelloController">
<p>{{greeting.text}}</p>
</div>
</body>
The JS part JS部分
var app = angular.module('myApp', []);
app.controller('HelloController',
function($scope) {
$scope.greeting = {
text: "Hello"
};
}
);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.