How do you attach an EventEmitter output to a component under routing?

I have a route configuration

@RouteConfig([ { path: '/', name: 'Start', component: Journal }, { path: '/register', name: 'Register', component: Register }, { path: '/login', name: 'Login', component: Login }, { path: '/settings', name: 'Settings', component: Settings }, ]) 

I would like to listen to events released from @Output magazine. How can I do this when the only link I have in the template is

 <a class="nav-item nav-link" [routerLink]="['Journal']">Journal</a> 

?

+6
source share
1 answer

I understand that now it is quite old, but the transfer of state to the route is canceled. This is mainly due to the fact that routerLink is common and can accept any number of potential children. Therefore, even if you can pass a state or process its events, you will get unnecessary complexity.

The correct way to manage state between parent and child components is a common service . Essentially, it comes down to the following steps:

  • Write a service.
  • Provide the service not from your module, but from the parent component (to make it inaccessible to external code).
  • Contribute the service to the parent and any children that need it.

This will work equally well with the state passed to the child, and with notifications received from the child, and will not pollute the route setting.

0
source

All Articles