简体   繁体   中英

How to use ng-container with ng-content (with select tag) in angular 4

How do you use ng-container in combination with ng-content that has a select tag.

<div class="container">
  <div id="first">
    <ng-container *ngTemplateOutlet="widgetContent"></ng-container>
  <div>
  <div id="second">
    <ng-container *ngTemplateOutlet="widgetContent"></ng-container>
  </div>
</div>

<ng-content #widgetContent select="side-widget, [sidewidget]"></ng-content>

Try this

<div class="container">
   <div id="first">
      <ng-container [ngTemplateOutlet]="widgetContent"></ng-container>
   <div>
   <div id="second">
      <ng-container [ngTemplateOutlet]="widgetContent"></ng-container>
   </div>
</div>

<ng-template  #widgetContent>
   <ng-content></ng-content>
</ng-template>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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