Angular2 - 获取json值以将值替换为html模板

时间:2016-12-01 12:31:20

标签: html angular typescript

angular2的新功能,在从Footer []数组中输出值并显示它时出现问题。

footer.component.ts:

import { Component } from '@angular/core';

export class Footer {
  id: number;
  value: string;
}

const FOOTER : Footer[] = [
    {id: 1, value: 'value_one'},
    {id: 2, value: 'value_two'}
  ];

@Component({
    selector: 'footer',
    template: `<html-outlet [html]="footerValue"></html-outlet>`,
})
export class FooterComponent{
    foot = FOOTER;

    footerValue = `<div class="menu" *ngFor="let f of foot" >
                <div class="footer"><b>{{f.value}} @2016</b></div>
            </div>`;
}

罪恶:

template:`<html-outlet [html]="footerValue"></html-outlet>`,

从&#39; footerValue&#39;获取模板并发送到另一个函数来动态编译和加载html。

如果它直接传递为:

,则一切正常
template: `<div class="menu" *ngFor="let f of foot" >
                <div class="footer"><b>{{f.value}} @2016</b></div>
            </div>`,

有人可以指导我如何将数组中的值附加到字符串变量&#39; footerValue&#39;,以跟随我的原始功能以动态生成html。

原始html模板是:

`<div class="menu" *ngFor="let f of foot" >
                <div class="footer"><b>Example @2016</b></div>
            </div>`

其中&#39;示例&#39;应该替换为数组中的值。

0 个答案:

没有答案