How to Display Typescript code in Html

前端 未结 1 1312
情深已故
情深已故 2021-01-02 17:21

I want to display a component\'s code in a Html template, Not the value generated by the code but the actual code.

like this

   import { Injectable }         


        
相关标签:
1条回答
  • 2021-01-02 17:49

    Use a variable in your ts file that contains all the code and display it in html using this {{stringThatContainsAllTheCode}}

    I think the simplest way is to use [innerHTML]="varContainingCode" and hold the code in the components class

    <pre>
      <code [innerHTML]="code"></code>
    </pre>
    
    export class AppComponent {
      code = `   //type script code`
    }
    

    Or if you don't want to use this library call ng2-prism can be useful.

    This is a Angular2 codeblock highlighting component library.

    0 讨论(0)
提交回复
热议问题