0
這裏是代碼我得到了一個未定義當我搜索使用GitHub的API與angularjs
視圖代碼:
<input type="text" class="form-control" ng-model="model.org" />
<input type="button" class="btn btn-primary" value="Load Repos" ng-click="getRepos(model.org)" ng-hide="model.repos" />
<div class="col-md-6">
<table class="table table-striped" ng-show="model.repos">
<tr>
<th>Name</th>
<th>Language</th>
<th></th>
</tr>
<tr ng-repeat="r in model.repos">
<td>
<h4>{{r.name}}</h4> {{r.description}}
</td>
<td>{{r.language}}</td>
<td><input type="button" class="btn btn-success" ng-click="loadDetail(r.name)" value="Detail"> </td>
</tr>
</table>
</div>
,這是控制器內部:
$scope.model = {
number: 0,
result: 'Ready'
};
$scope.getRepos = getRepos;
function getRepos(org) {
$http.get('https://api.github.com/orgs/org/repos').then(function(response) {
$scope.model.repos = response.data;
}, function(response) {
alert(response.error);
$scope.model.repos = 'Error: ' + response.data.message;
})
}
當我點擊具有ng-click =「getRepos(javascript)」的按鈕;但是如果我將此鏈接https://api.github.com/orgs/javascript/repos複製到瀏覽器,它將返回數據!
我在這裏錯過了什麼?
是什麼'getRepos(JavaScript的)的說法''javascript'的HTML裏面?它必須是一個範圍變量,否則你會得到未定義的。 – CozyAzure
您的網址https://api.github.com/orgs/org/repos不會返回任何數據 – Dario
@CozyAzure我更新了代碼以使其更清楚 – Abdulrhman