我想從返回函數中獲取JSON對象數組,並使用ng-repeat在此數組中循環,但它不適用於我,這是我的代碼:
var app=angular.module("myApp",[]);
app.controller("myController",function($scope,$http){
$scope.listOfFields=[];
$scope.getlistOfFieldsByIdTable = function(idTable)
{
$http.get("/listOfFieldsByIdTable/"+idTable)
.success(function(data){
return data;
});
};
});
<!-- first call -->
<!-- 150 is the id of the table-->
<div class="panel-body" ng-app="myApp" ng-controller="myController">
<ul ng-init="listOfFields = getlistOfFieldsByIdTable(150)">
<li ng-repeat="field in listOfFields ">
{{field.name}}
</li>
</ul>
</div>
<!-- second call -->
<div class="panel-body" ng-app="myApp" ng-controller="myController">
<ul>
<lib ng-repeat="field in getlistOfFieldsByIdTable(150)">
{{field.name}}
</li>
</ul>
</div>
,我使用的不是爲我工作了兩個電話,當我用像 「谷歌瀏覽器高級REST客戶端插件」一RESTClient實現我的服務工作正常,你可以幫我如何正確地調用我的數組對象,並在我的HTML頁面中顯示結果, 感謝先進。
將您的結果記錄在您的獲取功能中。你有什麼收穫? –
嗨@JeremyJackson感謝您的回覆,是的,我用了一個 函數(error){ console.log('something went wrong'); });但我沒有得到任何錯誤的功能,我的問題在我的HTML頁面呈現結果的方式:( – James
這很好,但嘗試記錄你回來的迴應,而不僅僅是一個錯誤。只是想確保您實際上正在獲取數據以進行渲染,並且嘗試在控制檯中調用該函數,並查看是否還有任何東西。 –