首页 文章

如何将angular2检索数据用作html标签?

提问于
浏览
3

我在angular2中读取一个json文件 . 到目前为止,我能够从json文件中获取数据 . 我在项目中创建了几个angular2组件,这些组件在此数据中有选择器 . 我想使用此数据作为html标记加载我的所有组件 . 即如果我得到 col.uiComponent="HEADING" ,那么我想用它作为

<HEADING></HEADING>

所以,我需要这样做

<col.uiComponent> Loading.. </col.uiComponent>

我尝试使用此代码:

<div *ngFor="#srColumn of sRow.secRowColumns">                        
   <{{srColumn.uiComponent}}>Loading </{{srColumn.uiComponent}}>                       
</div>

Child Component

@Component({
selector: 'DYNAMIC-BODY-1',    
templateUrl: 'app/DYNAMIC-BODY-1/DYNAMIC-BODY-1.component.html'   
})

DYNAMIC-BODY-1.component.html

<div class="col-sm-4 divDynamic">
    <table  style="width:100%;">
        <tr style="background-color:#B8B8B8">
            <th>{{comp.data}}</th>
        </tr>
        <tr>
            <td>&nbsp;</td>
        </tr>
    </table>
    
</div>

使用DynamicComponentLoader我这样做了 .

constructor(dcl: DynamicComponentLoader, injector: Injector,private dataService: DataService) {
    dcl.loadAsRoot(DynamicBody1Component, 'DYNAMIC-BODY-1', injector);
 }

我的子组件有选择器“DYNAMIC-BODY-1”它显示我的错误,如:

EXCEPTION: The selector "DYNAMIC-BODY-1" did not match any elements

Plz帮助 .

1 回答

相关问题