How to copy NgTemplate and NgTemplate Outlet with Inheritance or something else in Angular

江枫思渺然 提交于 2020-01-15 11:36:48

问题


We have a Component with Typescript business logic, and then Html formatting. The marketing department wants to create a different html format/orientation, with Same Business logic.

To extend the Same business Typescript logic, we are utilizing Inheritance and extends as quick and easy way.

For html formatting, say Div A, Div B, Div C, will be arranged in different orders and formats, with some additional changes . We have NgTemplate and NgTemplateOutlets for each Div defined in the original Component.

When trying to invoke utilize the ngTemplate Outlets in the inheritance component, we are noticing they are not showing.

Question is, how do I share ng-template Outlets to the new Inheritance Component?

Original Typescript

export class OriginalClass {

Original Component html:

<ng-container *ngTemplateOutlet = "templateref1"></ng-container>
<ng-container *ngTemplateOutlet = "templateref2"></ng-container>

// they are defined in bottom of html here
<ng-template #templateref1>
    hello
<ng-template>
<ng-template #templateref1>
    hello2
<ng-template>

New Typescript class Inheritance :

export class NewClass extends OriginalClass {

New Component html: trying to call ng-templates without redefining them

<ng-container *ngTemplateOutlet = "templateref2"></ng-container>
<ng-container *ngTemplateOutlet = "templateref1"></ng-container>

来源:https://stackoverflow.com/questions/59556065/how-to-copy-ngtemplate-and-ngtemplate-outlet-with-inheritance-or-something-else

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!