我使用节点js和角度js和把手作为视图引擎。我正在尝试基本的应用程序/示例,但没有在浏览器端获取任何数据。浏览器上的数据显示为空白。
我在浏览器上做了console.log,我把数据作为[object] [object]。
Included angular:
<script
src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js">
</script>
On handlebars page : [enter image description here][1]table:
<table ng-controller="myCtrl" border="1">
<li ng-if="records.length === 0">( No items in this list yet! )</li>
<tr ng-repeat="x in records">
<td>{{x.Name}}</td>
<td>{{x.Country}}</td>
</tr>
</table>
<script>
var app = angular.module('tennisApp',[]);
app.controller('myCtrl', function($scope, $http) {
$scope.data = [];
var request = $http.get('http://localhost:3030/aitaAngular');
request.success(function(response) {
$scope.data = response;
console.log(response);
console.log($scope.data);
});
request.error(function(response){
console.log('Error: ' + response);
});
});
</script>
答案 0 :(得分:0)
那里有你错误的控制器名称。 您在视图中使用了 myCrtl ,在javascript中使用了 userDetails ng-app 也没有
<!DOCTYPE html>
<html>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script>
<body>
<div ng-app="myApp">
<table ng-controller="userDetails" border="1">
<li ng-if="records.length === 0">( No items in this list yet! )</li>
<tr ng-repeat="x in records">
<td>{{x.Name}}</td>
<td>{{x.Country}}</td>
</tr>
</table>
</div>
<script>
var app = angular.module('myApp', []);
app.controller('userDetails', function($scope, $http) {
$scope.data = [];
var request = $http.get('http://localhost:3030/aitaAngular');
request.success(function(response) {
$scope.data = response;
console.log(response);
console.log($scope.data);
});
request.error(function(response){
console.log('Error: ' + response);
});
});
</script>
</body>
</html>