Recursive component loading with recursive array

后端 未结 3 797
南方客
南方客 2021-01-23 15:11

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:



        
3条回答
  •  青春惊慌失措
    2021-01-23 15:36

    I would create your component this way:

    @Component({
      selector: 'my-item',
      template: `
        
    ` }) export class MyItemComponent { @Input() data: any; }

    and call it the component from another component and provide the whole component data:

    @Component({
      selector: 'other-comp',
      template: `
        
      `
    })
    export class OtherComponent {
      wholeData = [
        {
          "id": 1,
          "text": "abc"
        },
        (...)
      ];
    }
    

提交回复
热议问题