Last active
August 26, 2019 06:15
-
-
Save anvaypatil/425da5ddc735e74356ab2b218786862f to your computer and use it in GitHub Desktop.
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
// TemplateContext.ts | |
export interface TemplateContext { | |
a: string; | |
b: string; | |
c: string; | |
} | |
---------------------------------------------------------------------------------------------------- | |
// App.component.ts | |
@Component({ | |
selector: 'app-root', | |
template: ' | |
<app-template-parent [layoutTemplate]="element" [templateContext]="context"></app-template-parent> | |
<ng-template #element let-object> | |
context -> {{object | json}} | |
</ng-template> | |
' | |
}) | |
export class AppComponent { | |
context: TemplateContext = { | |
a: 'aaaa', | |
b: 'bbbb', | |
c: 'cccc' | |
}; | |
} | |
---------------------------------------------------------------------------------------------------- | |
//template-parent.component.ts | |
@Component({ | |
selector: 'app-template-parent', | |
template: ' | |
<ng-container *ngTemplateOutlet="layoutTemplate; context: {$implicit: templateContext}"> | |
</ng-container> | |
' | |
}) | |
export class TemplateParentComponent implements OnInit { | |
@Input() templateContext: TemplateContext; | |
@Input() layoutTemplate: TemplateRef<TemplateContext>; | |
ngOnInit() { | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment