【发布时间】:2017-07-09 00:31:29
【问题描述】:
我有一个关于角度 2 的问题。 所以我可以使用 ngFor 从本地 json 显示 {{data}} 标签并显示数据。
但是我想知道是否有一种方法可以渲染存储在 json 中的组件选择器标签并将它们显示在 ng for 中。例如, 我的文件中有这个 json component.ts:(有关该问题的说明,请参阅 cmets)
import { Component, OnInit } from '@angular/core';
import * as jQuery from 'jquery';
@Component({
selector: 'app-dashboard',
templateUrl: './dashboard.component.html',
styleUrls: ['./dashboard.component.css']
})
export class DashboardComponent implements OnInit {
widgets;
constructor() { }
ngOnInit() {
this.widgets = [
{
"widgetcode": "<app-analytics-widget></app-club-chooser>" //Existing component selector tag within the angular cli system
},
{
"widgetcode": "<app-club-chooser></app-club-chooser>" //Existing component selector tag within the angular cli system
},
{
"widgetcode": "<app-account-widget></app-account-widget>" //Existing component selector tag within the angular cli system
}
]
}
}
我的 component.html 文件:
<div class="DahsboardWrapper">
<!-- DashBoard Ges here -->
<!-- widget elements go here -->
<div class="DashoardHeaderClass" id="dashboard">
Dashboard Loaded
<div class="WidgetAreaWrapper">
<div class="widgets" *ngFor="let widget of widgets">
<!-- {{widget.widgetcode}} Not working atm..-->
<!-- this is displayng just plain text -->
</div>
<!-- This is working -->
<app-analytics-widget></app-analytics-widget>
<app-club-chooser></app-club-chooser>
<app-account-widget></app-account-widget>
</div>
</div>
有什么建议可能有更好的方法吗?
【问题讨论】:
标签: javascript jquery html angular angular-cli