I want to get an array of JSON objects from a return function and loop inside this array using ng-repeat, but its not working for me.
This is my code :
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>
<li ng-repeat="field in getlistOfFieldsByIdTable(150)">
{{field.name}}
</li>
</ul>
</div>
The two calls that I used are not working for me, my service works fine when i used a RestClient like "Advanced Rest Client plugin in Google Chrome".
How can I property call my array of objects and show the results in my HTML page?