I need to create a parent component, which encapsulates some ui-logic (in component.ts) as well as some template logic (component.html) for some child components.
For template inheritance we use ng-content, and the htmls look like this:
app.component.html:
<parent [parentsInput]='X'>
<child1></child1>
</parent>
<parent [parentsInput]='Y'>
<child2></child2>
</parent>
<parent [parentsInput]='Z'>
<child3></child3>
</parent>
parent.component.html
<div>
... {{parentsInput}}
</div>
<ng-content></ng-content> <!-- dynamic content where child templates are injected -->
<div>
... {{parentsInput}}
</div>
child.component.html
<div>
... {{parentsInput}}
</div>
And i also define the parentComponent as "parent" of child like this:
export class ChildComponent extends ParentComponent
So, what I have now: The html is rendered correctly, so i really see in browser that the child template is contained within the parents template in correct position.
But the problem is: Child component cannot access the parent's attributes (i.e. parentsInput). In Webstorm it actually looks good, you click on the attribute name from child component, and you are navigated to parent component where the attribute is actually defined. But it somehow does not work in Browser. How can we achieve this, so that the child components can use the parents attributes as their own attributes?
PS: i have figured out that we can inject the parent component as a dependency (sth. like @Inject(ParentComponent) parent: ParentComponent in constructor) and access the attributes, but this is not what i want since our child components may read & modify many attribute, i do not want to read all attributes separately. I would like to have an "inheritance".