AngularJS Question

2 Json document associate and nested in angularJS

I have two json. For example

1

[ {"id":"23", "name":"mehmet"} , {"id":"22", "name":"jack"} ]


2

[ {"id":"1", "userID":"23"} , {"id":"2", "userID":"23"}, {"id":"3", "userID":"22"}]


in the first json mehmet have 2 entries second json ( associate userID )

I want to...

mehmet (source first json)
id:1 (second json)
id:2 (second json)

jack(source first json)
id:3 (second json)


My controller:

.controller('ListviewCtrl', function($scope, $http, SERVER) {

$scope.topics = [];
function loadTopics(params, callback){
$http.get(SERVER.url+'/listtopic', {params: params})
.success(function(response){
var topics = [];

angular.forEach(response, function(result){


topics.push(result);
});

callback(topics);
});
};



$scope.tweetler = [];
function loadTweetler(params, callback){
$http.get(SERVER.url+'/tweet')
.success(function(response){
var tweetler = [];

angular.forEach(response, function(result){
tweetler.push(result);
});
callback(tweetler);
});
};


how to use ng-repeat and list associate 2 json ?

Answer

You can create a filter inside the child ng-repeat, as follows:

var app = angular.module('app', []);

app.controller('mainCtrl', function($scope) {
  $scope.parents = [  
     {  
        "id":23,
        "name":"mehmet"
     },
     {  
        "id":22,
        "name":"jack"
     }
  ];

  $scope.childs = [  
     {  
        "id":1,
        "userID":23
     },
     {  
        "id":2,
        "userID":23
     },
     {  
        "id":3,
        "userID":22
     }
  ];
});
<!DOCTYPE html>
<html ng-app="app">

<head>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.5.7/angular.min.js"></script>
</head>

<body ng-controller="mainCtrl">
  <ul>
    <li ng-repeat-start="parent in parents" ng-bind="parent.name"></li>
    <ul ng-repeat-end ng-repeat="child in childs | filter: { userID: parent.id }">
      <li ng-bind="'Id:' + child.id"></li>
    </ul>
  </ul>
</body>

</html>