简体   繁体   English

Angular 6使用ngFor循环和插值渲染HTML标签

[英]Angular 6 rendering HTML tag with ngFor loop with interpolation

i'm having a problem with template rendering (ANGULAR 6) and a library for creating floating panels ( jsPanel 6 ) that is plain javascript. 我在模板渲染(ANGULAR 6)和用于创建浮动面板( jsPanel 6 )的库中遇到问题,该库是纯JavaScript。 To sum up: 总结一下:

In my template, after rendering it, i have one BUTTON that triggers this function: 在我的模板中,渲染后,我有一个触发该功能的按钮:

public openPanel()
  {

    let list: Array<number> = [1, 2, 3];

    let tag : string = '<ul> <li *ngFor="let i of list"> {{ i }} </ul>';

      jsPanel.create({
        theme:       'primary',
        contentSize: {
            width: function() { return Math.min(730, window.innerWidth*0.9);},
            height: function() { return Math.min(400, window.innerHeight*0.5);}
        },
        position:    'center-top 0 250',
        animateIn:   'jsPanelFadeIn',
        headerTitle: 'I\'m a jsPanel',
        content:     tag,
        onwindowresize: true
    });

  }

The problem is that Angular doesn't render the ngFor, it doesn't go trough the loop and also, it doesnt get the ``{{ i }}´´ interpolation. 问题在于Angular不会渲染ngFor,它不会经过循环,而且也不会得到“ {{i}}”插值。 I'm using typescript by the way. 我正在使用打字稿。

result after clicking the button 单击按钮后的结果

Is there away without using Dynamic Component Loader to render that?. 是否有没有使用Dynamic Component Loader渲染的地方?

Thanks 谢谢

Obviously it does not working. 显然它不起作用。 Why don't you construct HTML with javascript as follows ? 您为什么不使用javascript构造HTML呢?

public openPanel()
  {

    let list: Array<number> = [1, 2, 3];

    let tag: string = list.map(i => 
      `<ul><li>${i}</ul>`
    ).join('');

      jsPanel.create({
        theme:       'primary',
        contentSize: {
            width: function() { return Math.min(730, window.innerWidth*0.9);},
            height: function() { return Math.min(400, window.innerHeight*0.5);}
        },
        position:    'center-top 0 250',
        animateIn:   'jsPanelFadeIn',
        headerTitle: 'I\'m a jsPanel',
        content:     tag,
        onwindowresize: true
    });

  }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM