title: How to filter the subnodes of a tree using recursion in angular2
body: <pre><code>--**app.component.ts**
  import { Component,OnInit } from '@angular/core';
  import { Observable } from 'rxjs/Observable';
  import { Subject } from 'rxjs/Subject';
  
  
  @Component({
    selector: 'my-app',
    templateUrl:'./app.component.html'
  })
  export class AppComponent implements OnInit {
    Tree: any;
    private searchText$ = new Subject&lt;string&gt;();
    ngOnInit() {
      this.Tree = this.myTree;
    }
  
    myTree  = [
      { name: "parent1", subnodes: [{ name: "parent1_child1", subnodes: [{ name: "parent_child1_child1", subnodes: [] }] },{ name: 'parent1_child2', subnodes: [] }]  },
        {
            name: "secondparent2",
            subnodes: [
              { name: "secondparent2_child1", subnodes: [] }
            ]
        },
          {
            name: "thirdparent3",
            subnodes: [
                {
                name: "Chandigarh3",
                    subnodes: [
                      { name: "parent3_child1_child1", subnodes: [] }
                    ]
                }
            ]
        }
    ];
  
    filter(name: string):any {
  
      this.Tree = this.myTree.filter(data =&gt; data.name.match(name) || (data.subnodes.filter(subnode =&gt; (subnode.name.match(name))).length &gt; 0) ? true:false);
  
    }
  
    search(input: string, data: any): boolean {
     let output= data.subnodes.filter(subdata =&gt; (subdata.name.match(name)))
     if (output != undefined &amp;&amp; output.length &gt; 0) {
       return true;
     }
     else {
       return false;
     }
  
      }
  
    }
  
  
  --**app.component.html**
  &lt;h1&gt;Tree as UL&lt;/h1&gt;
  &lt;tree-view [treeData]="Tree"&gt;&lt;/tree-view&gt;
  &lt;input   type="text"  (keyup)="filter($event.target.value)"  /&gt;
  </code></pre>
  
  <p>I am able to filter first parent nodes and corresponding subnodes but after that how to filter subnodes?
  I have written search function so i can invoke search method from filter method by passing the input and tree , I want to use search method recursively</p>