如何在离子2中渲染动态组件

时间:2016-12-09 08:00:15

标签: angular ionic2

我需要渲染按钮,但它不起作用 我用离子2

  

home.ts

import { Component } from '@angular/core';
    import { NavController } from 'ionic-angular';

    @Component({
      selector: 'page-home',
      templateUrl: 'home.html'
    })
    export class HomePage {
      content:string ='<button ion-button color="light">Light</button>';
      constructor(public navCtrl: NavController) {
      }
    }
  

home.html的

<ion-content>
<ion-card>
    {{content}}
</ion-card>
</ion-content>

This result

1 个答案:

答案 0 :(得分:1)

将代码更改为<ion-card [innerHtml]="content"></ion-card>

{{content}}只会将值打印为字符串。但innerHtml实际上会使用原始html数据