【发布时间】:2015-06-28 13:15:18
【问题描述】:
我是网页设计和 Angular 的新手,我正在复制类似于 this 的内容,我在其中使用 RESTful Web 服务并使用 AngularJS 在 JSON 中显示信息。
它似乎对我不起作用。我的 main.jsp 文件如下所示:
<!doctype html>
<html ng-app>
<head>
<title>Your Bill</title>
<!-- Include the AngularJS library -->
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.5/angular.min.js"></script>
<!-- BillParser script -->
<script type="text/javascript" src="js/app.js"></script>
</head>
<body>
<div ng-controller="GetBill">
<p>The ID is {{bill.id}}</p>
<p>The content is {{bill.content}}</p>
</div>
</body>
</html>
我的 app.js 看起来像:
function GetBill($scope, $http) {
$http.get('http://rest-service.guides.spring.io/greeting').
success(function(data) {
$scope.bill = data;
console.log('INITTED');
});
}
但是在 localhost/billparser/index 上看起来像下面这样:
The ID is {{bill.id}}
The content is {{bill.content}}
我在这里有什么明显的遗漏吗?请原谅“账单”的命名,它最终将与账单有关,我只想让 Angular 先工作!
我似乎收到以下错误:
https://docs.angularjs.org/error/ng/areq?p0=GetBill&p1=not%20a%20function,%20got%20undefined
我需要做什么来解决这个问题?我以前从未使用过 js,所以这对我来说是全新的!
感谢您的宝贵时间。
【问题讨论】:
标签: javascript angularjs