2017-04-21 67 views
0

我試圖獲得一個基本的angular.js頁面來顯示使用來自node.js服務器的http get請求檢索到的信息。然而我遇到的問題角度不能識別我正在得到的JSON或沿着這些線的東西。下面是index.html的json數據不被識別爲行(angular.js)

<!DOCTYPE html> 
<html > 
<script 
    src="http://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"> 
</script> 
<body> 

<div ng-app="myApp" ng-controller="customersCtrl"> 
<h1>{{names}}</h1> 
<table> 
<tr ng-repeat="x in names"> 
    <td>{{ x.title }}</td> 
    <td>{{ x.pBody }}</td> 
    <td>{{ x.category }}</td> 
    <td>{{ x.url }}</td> 
</tr> 
</table> 

</div> 

<script> 
var app = angular.module('myApp', []); 
app.controller('customersCtrl', function($scope, $http) { 
$http.get("http://127.0.0.1:8081/process_get") 
.then(function (response) {$scope.names = response.data;}); 
}); 
</script> 

,然後這裏是Node.js的app.js文件

var queryString = 'SELECT * FROM posts'; 
var retRows; 
connection.query(queryString, function(err, rows, fields) { 
if (err) throw err; 
    console.log(rows); 
    retRows = rows; 
}); 
app.get('/process_get', function (req, res) { 
// Prepare output in JSON format 
console.log(response); 
res.end(JSON.stringify(retRows)); 
}) 

相關片段終於如下,我認爲應該是正在顯示的JSON數據精細?

{"retRows":[{"id":1,"title":"global work and travel co.","pBody":"One of the 
worlds leading and largest youth travel 
brands","category":"Travel","url":"https://globalworkandtravel.com"}, 
{"id":2,"title":"travel.com.au","pBody":"One destination endless 
possibilities","category":"Travel","url":"https://www.travel.com.au"}, 
{"id":3,"title":"Flight Centre","pBody":"Australias leading travel 
agent","category":"Travel","url":null},{"id":4,"title":"The skinny 
confidential","pBody":"lifestyle 
blog","category":"Lifestyle","url":"https://www.theskinnyconfidential.com"}, 
{"id":5,"title":"three years of travel","pBody":"Three years of travel and 
adventure from around the 
world","category":"Video","url":"https://www.youtube.com/watch? 
v=wJF5NXygL4k"}]} 

任何幫助,因爲我在做什麼不正確或提示我在哪裏可以找到更多的信息將不勝感激。

回答

1

你將不得不提及的namesretRows財產在NG-重複指令:

<tr ng-repeat="x in names.retRows">