I wanna show all Ingredient of each recipes, I created a 2d array and push each name of Ingredient of each recipe, outputting all ingredient in console is no problem( console.log($scope.listOfIngredient[i][j].Ingredient.name) is working) ,but console.log($scope.listOfIngredient) doesn't work, which make me confused, and another thing is that listOfIngredient in html file just contains one random ingredient of recipe, as you see picture below code, browser always can only show one recipe Ingredient, but console.log($scope.listOfIngredient) shows nothing in this listOfIngredient.
var myApp = angular.module('myApp', []);
myApp.controller('mainController', function($scope, $http) {
$scope.listOfRecipe = null;
var url = "http://164.132.196.117/chop_dev/recipe/recipes.json";
var url2 = "http://164.132.196.117/chop_dev/recipe/recipes/view/";
$http({
method: 'GET',
url: url
}).then(function(response) {
$scope.listOfRecipe = response.data.recipes;
var recipeLength = $scope.listOfRecipe.length;
$scope.listOfIngredient = new Array(recipeLength);
console.log(recipeLength);
for (var i = 0; i < recipeLength; i++) {
$http({
method: 'GET',
url: url2 + response.data.recipes[i].Recipe.id + ".json"
}).then(function(response2) {
var IngredientLength = response2.data.recipe.IngredientMapping.length;
console.log(IngredientLength);
for (var j = 0; j < IngredientLength; j++) {
$scope.listOfIngredient[i] = new Array(IngredientLength);
}
for (var j = 0; j < IngredientLength; j++) {
$scope.listOfIngredient[i][j] = response2.data.recipe.IngredientMapping[j];
console.log($scope.listOfIngredient[i][j].Ingredient.name);
/* $scope.listOfIngredient[i].push(response2.data.recipe.IngredientMapping[j]); */
}
});
}
console.log($scope.listOfIngredient);
})
});
<div ng-app="myApp" ng-controller="mainController" class="center">
<div class="container-fluid">
<div class="ingredientMapping2" ng-repeat="recipes in listOfIngredient track by $index ">
<ul>{{recipes}}</ul>
<ul>
<li ng-repeat="x in recipes track by $index ">
{{x.Ingredient.name}}
</li>
</ul>
</div>
</div>
</div>

$scopeinstead of usingconsole.log()