Skip to content

Instantly share code, notes, and snippets.

@anvaypatil
Last active August 26, 2019 06:15
Show Gist options
  • Save anvaypatil/425da5ddc735e74356ab2b218786862f to your computer and use it in GitHub Desktop.
Save anvaypatil/425da5ddc735e74356ab2b218786862f to your computer and use it in GitHub Desktop.
// 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