角嵌套动态分量

问题描述 投票:0回答:1

我想根据给定的json动态创建组件。第一层是TestComponent,它可以具有许多TestLayerComponent。问题是TestLayerComponent也可以具有许多TestLayerComponents。我使用它来动态地创建幻灯片推式菜单。如果Layer路径以Europe开头创建带有文本欧洲的

  • ,如果欧洲有巴尔干,则使用
  • 巴尔干等在欧洲创建新的。菜单必须看起来为like this,但使用不是DOM的组件来实现。
        [{
      Username:"",
      Password:"",
      Maps:[
        {
        Name:"",
        Title:"",
        Layers:[
           id:""
           path:"Europe/Balkans/Greece"
         ]
       },
    
        {
        Name:"",
        Title:"",
        Layers:[
           id:""
           path:"Europe/Balkans/Romania"
         ]
       },
      {
        Name:"",
        Title:"",
        Layers:[
           id:""
           path:"Asia/China"
         ]
       },
      ]
    
    }
    ]
    

    这是我尝试的代码,但仍仅显示最后一个组件。

    for (const map of maps) {
      mapViewContainerRef.clear();
      let mapRow = mapViewContainerRef.createComponent(mapFactory);
      mapRow.instance.maps = map;
      for (const layer of map.layers) {
        mapFactory = this.menuFactory.resolveComponentFactory(TestLayerComponent);
        mapViewContainerRef.clear();
        mapViewContainerRef.createComponent(mapFactory);
        mapRow = mapViewContainerRef.createComponent(mapFactory);
        mapRow.instance.layers = layer;
      }
      mapRow.destroy();
    }
    
  • angular angular-directive
    1个回答
    0
    投票
    for (const map of maps) {
      mapViewContainerRef.clear();
      let mapRow = mapViewContainerRef.createComponent(mapFactory);
      let index = 1;
      mapRow.instance.maps = map;
      for (const layer of map.layers) {
        mapFactory = this.menuFactory.resolveComponentFactory(TestLayerComponent);
        mapRow = mapViewContainerRef.createComponent(mapFactory, index);
        index++;
      }
    }
    
    © www.soinside.com 2019 - 2024. All rights reserved.