我有什么想法,这个ng-repeat错了吗?表格中没有显示任何使用ng-repeat的内容。
HTML:
<div ng-app="myApp">
<div ng-controller="conn1">
<button ng-click="fetch()">fetch</button><br/>
user name: {{user.name}}<br/>
<p>
<table>
<tr><td>name</td></tr>
<tr ng-repeat="auser in everyuser">
<td>{{auser.name}}</td>
</tr>
</table>
</p>
</div>
</div>
角:
var myApp = angular.module("myApp", []);
var conn1 = myApp.controller("conn1", function($scope, $http){
var onFetchDone = function(response){
$scope.user = response.data;
$http.get($scope.user.repos_url)
.then(onGetAllDone);
};
$scope.onGetAllDone = function(response){
$scope.everyuser = response.data;
};
$scope.fetch = function(response) {
$http.get("https://api.github.com/users/gabrielecirulli")
.then(onFetchDone);
};
});
答案 0 :(得分:1)
onGetAllDone
是在范围对象上定义的。因此,您需要在其前面添加$scope
$http.get($scope.user.repos_url).then($scope.onGetAllDone);
答案 1 :(得分:1)
您的函数onGetAllDone
被设置为作用域对象的属性,promise chaining不会自动从作用域中评估函数引用。
相反,只需将其定义为:
function onGetAllDone(response){
$scope.everyuser = response.data;
};
或者将其设置为:
.then($scope.onGetAllDone)
<强> Demo 强>