我正在尝试使用AngularJS和NodeJS来显示我在数据库中的表中的用户。问题是用户没有在我的表中显示,尽管可以通过console.log($ scope.users)看到它们。我在模板中使用了ng-repeat:
$<table>
<tr>
<th>Id</th>
<th>Name</th>
<th>Email</th>
</tr>
<tr ng-repeat = "user in users">
<td>{{ user.id }}</td>
<td>{{ user.name }}</td>
<td>{{ user.email}}</td>
</tr>
</table>
这是我用来从数据库中获取用户的控制器代码:
myApp.controller('registerController', ['$scope', '$http', function($scope, $http) {
$scope.message = 'This is the register screen'
var refresh = function() {
$http.get('/users')
.then(function(response) {
console.log("I got the data I requested")
$scope.users= response
console.log($scope.users)
})
}
refresh()
}])
答案 0 :(得分:1)
{{ user.name }}
不是{{ users.name }}
答案 1 :(得分:0)
你也可以使用then函数。
你将在response.data中获取数组。
响应还包含其他信息以及标题,状态,数据等。