As my Title, I'd like to get parent data from nested json. I know how to do it in HTML. And I'd like to know how to do it in controllers.
Here is my directive with nested json
.factory('dataFac', function(){
return {
parents : [{
name: 'George',
age: 44,
children: [{
name: 'Jack',
age: 16
},{
name: 'Amy',
age: 13
}]
}, {
name: 'Jimmy',
age: 38,
children: [{
name: 'Max',
age: 7
},{
name: 'Lily',
age: 5
},{
name: 'Kim',
age: 4
}]
}]
}})
Controller
.controller('dataCtrl', function($scope, $location, dataFac) {
$scope.data = dataFac.parents;
//here I'd like to get name of parents
$scope. = ;
//here I'd like to get name of children
$scope. = ;
//and when I get the data of the children, I can get their parents' name
$scope. = ;
console.log($scope.navbars.id);
$scope.isActive = function(route) {
return route === $location.path();
};})
Appreciate if someone could help.
$scope.data[i].name?$scope.datathen?