I\'m trying to load an Angular 2 component recursively with a recursive array (plunk: http://plnkr.co/edit/3npsad?p=preview).
Given this recursive array:
Heres something to get your started. You need to implement the HTML returning function yourself:
var a = [
{
"id": 1,
"text": "abc"
},
{
"id": 2,
"text": "def",
items: [
{
"id": 21,
"text": "def-1",
items: [
{
"id": 211,
"text": "def-1-1"
},
{
"id": 212,
"text": "def-1-2"
}
]
},
{
"id": 22,
"text": "def-2"
}
]
}
];
function iterateRecursive(array) {
for(var i = 0; i < array.length; i++) {
if(array[i].items) {
console.log(array[i].text);
//uncomment: printHtml(array[i].id, array[i].text);
iterateRecursive(array[i].items)
} else {
console.log(array[i].text);
}
}
}
iterateRecursive(a);
//implement this function that takes an id and text and returns html
//call it in place of console log
function printHtml(id, text) {
}