I want to implement a navigation bar using json data which is fetched by angular service. I ave my service and controller working great, but I am unable to render the nested json data into my view. Below is my json data:
{
"menu": [
{
"name": "Electronics",
"link": "1",
"sub": [
{
"name": "Mobiles",
"link": "1.1",
"sub": [
{
"name": "Samsung",
"link": "1.1.1",
"sub": null
},
{
"name": "Apple",
"link": "1.1.2",
"sub": null
},
{
"name": "Motorola",
"link": "1.1.3",
"sub": null
},
{
"name": "Lenovo",
"link": "1.1.4",
"sub": null
},
{
"name": "Mi",
"link": "1.1.5",
"sub": null
},
{
"name": "Micromax",
"link": "1.1.6",
"sub": null
},
{
"name": "Oppo",
"link": "1.1.7",
"sub": null
},
{
"name": "Vivo",
"link": "1.1.8",
"sub": null
},
{
"name": "HTC",
"link": "1.1.9",
"sub": null
}
]
},
{
"name": "Mobile Accessories",
"link": "1.2",
"sub": [ ]
},
{
"name": "Laptop",
"link": "1.3",
"sub": [ ]
},
{
"name": "Laptop Accessories",
"link": "1.4",
"sub": [ ]
},
{
"name": "Appliances",
"link": "1.5",
"sub": [ ]
}
]
},
{
"name": "Men",
"link": "2",
"sub": [ ]
},
{
"name": "Women",
"link": "3",
"sub": [ ]
},
{
"name": "Baby & Kids",
"link": "4",
"sub": [ ]
},
{
"name": "Home & Furniture",
"link": "5",
"sub": [ ]
},
{
"name": "Books & More",
"link": "6",
"sub": [ ]
}
]
}
I am getting all the data in the console successfully, I just want help in rendering the data in the view using ng-repeat.
For reference, below is the controller and Factory Factory:
( function ()
{
angular.module( "myApp" )
.factory( "navService", function ( $http )
{
function getNavItems()
{
return $http.get( '../data/navData.json' );
};
return {
getNavItems: getNavItems
};
} );
}()
Controller:
( function ()
{
angular.module( "myApp" )
.controller( "NavController", function ( $scope, $http, navService )
{
navService.getNavItems().then( function ( menu )
{
$scope.menu = menu.data;
console.log( menu.data );
} );
} );
} ());
Thanks.