Skip to content

Instantly share code, notes, and snippets.

@zbarbuto
Last active July 25, 2019 07:03
Show Gist options
  • Save zbarbuto/cef2fdb799e6d2a21d3907bebace9278 to your computer and use it in GitHub Desktop.
Save zbarbuto/cef2fdb799e6d2a21d3907bebace9278 to your computer and use it in GitHub Desktop.
Template projection as a workaround for component restrictions
@Component({
selector: 'my-page',
template: `
<ion-content>
<ion-list><ion-item>My List</ion-item></ion-list>
<my-reusable-fab (templateOutput)="rootContent = $event"></my-reusable-fab>
<ng-template [ngTemplateOutlet]="rootContent"></ng-template>
</ion-content>
`
})
class MyPageComponent {
rootContent: TemplateRef;
}
@Component({
selector: 'my-reusable-fab',
template: `
<ng-template #templateContent>
<ion-fab padding vertical="bottom" horizontal="end" slot="fixed">
<ion-fab-button>
<ion-icon name="add"></ion-icon>
</ion-fab-button>
</ion-fab>
</ng-template>
`
})
class MyReusableFabComponent {
@Output() templateOutput = new EventEmitter();
@ViewChild('templateContent', { static: false }) set templateContent(template: TemplateRef) {
this.templateOutput.emit(template);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment