How to dynamically add innerHTML with angular 2 components

前端 未结 2 2162
鱼传尺愫
鱼传尺愫 2020-11-27 23:06

I\'m creating docs for a component library. I want 1 string of html that generates both the component on the page and the docs for it.

What I want:

2条回答
  •  萌比男神i
    2020-11-27 23:32

    I'll accept Gunter's answer since it answers my question.

    For those who are interested, the way I solved my problem was by creating a component and requiring it.

    I created a dumb component:

    import {Component} from '@angular/core';
    
    
    @Component({
      selector: 'flat-buttons',
      template: require('./flatButtons.html'),
    })
    export class FlatButtons {
    
      constructor() {
      }
    }
    

    And then my modified html template:

    Code Snippet

    {{getFlatButtons()}}

    And my modified component code:

    private flatButtons = require('./components/flatButtons/flatButtons.html')
    
    constructor() {}
    
    getFlatButtons() {
        return html_beautify(this.flatButtons, this.options)
    }
    

提交回复
热议问题