-1
15.html
<html>
<meta charset="utf-8">
<title>Angularjs htttp services</title>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.9/angular.min.js">
</script>
<script src="controller15.js"></script>
</head>
<body ng-app="mainApp">
<div ng-controller="people">
<ul>
<h2> names and ages of the programmers</h2>
<li ng-repeat="person in persons">
{{ person.Name +':' +person.Age}}
</li>
</ul>
</div>
</body>
</html>
controller15.js
var app=angular.module('mainApp',[]);
app.controller('people', function($scope,$http)
{
$http.get('database.json')
.success(function(response)
{
$scope.person=response.records;
});
});
database.json來存放各種信息:
{
"records":[
{
"Name":"mehul","Age":"13"
},
{
"Name":"ashok","Age":"23"
},
{
"Name":"rajesh","Age":"44"
}
]
}
我附上所有的代碼,請查看我的代碼。我是angularjs的初學者;如果您建議我使用特定的材料或網站,那將是非常好的。
請嘗試在這裏使用簡潔的標題:無論如何都不需要「Hi」和「Please help me」。我已經將你的代碼分成了幾個部分:如果你可以確保你爲每個文件使用一個代碼塊,它會更加可讀。謝謝。 – halfer