Вы можете просто передать то, что будет описывать ваш родительский компонент, дочернему элементу: @Input
.
Пример дочернего компонента:
@Component({
selector: 'child',
template: `
<div>{{ parentName }} is my parent</div>
`,
})
export class ChildComponent {
@Input() parentName: string;
}
Первый родитель:
@Component({
selector: 'first-parent',
template: `
<child-component parentName="'first-parent-component'" />
`,
})
export class FirstParentComponent {
}
Второй родитель:
@Component({
selector: 'second-parent',
template: `
<child-component parentName="'second-parent-component'" />
`,
})
export class SecondParentComponent {
}