AppComponent (parent) has main page (layout) and counter of pages:
export class AppComponent {
counter = '1/3';
}
<div class="counter">
{{counter}}
</div>
There are also two components (children) that are responsible for the content of pages. From child components, need to have access to the parent value (counter).
One of them:
import {AppComponent} from '../app.component';
export class Page1Component {
app: AppComponent;
}
SomeEvent($event) {
this.app.counter='2/3';
}
<div class="content">
...
</div>
After the event I get an error: "TypeError: Cannot read property 'counter' of undefined"
Question: How to manipulate a parent variable correctly?