How can I pass in generic HTML to an Angular 2 component?

后端 未结 1 642
野趣味
野趣味 2020-12-19 12:44

I want to make a generic modal component that can hold anything, from just text to images/buttons etc. If I do something like this:

相关标签:
1条回答
  • 2020-12-19 13:29

    What you are looking for is ng-content

     <div class="Modal">
       <div class="header"></div>
       <div class="body">
         <ng-content></ng-content>
       </div>
       <div class="footer"></div>
     </div>
    

    and you may pass any HTML content directly into your component. Lets say your component name is my-modal, you may use it like below,

      <my-modal>
         <<HTML content :  this will be replaced in the ng-content area >>
      </my-modal>
    

    Hope this helps!!

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