Last active
July 25, 2019 07:03
-
-
Save zbarbuto/cef2fdb799e6d2a21d3907bebace9278 to your computer and use it in GitHub Desktop.
Template projection as a workaround for component restrictions
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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