Provides a publish bus for the currently rendered component.
Why? Angular's router only provides the type of component being rendered for a specific route, but not the instance it has created for it. This service is a bridge which allows other services to get a hold of the instance of a currently rendered component.
How to use:
Use the publishComponent
directive on your <router-outlet>
element. This will hook into the outlet's activate
event and pass
the activated component to the bus service:
router-x/src/outlet/router-outlet-component-bus.service.ts
Properties |
|
Methods |
|
Accessors |
Public changes | ||||||||||
changes(outletName: string)
|
||||||||||
Gets an observable which can be used to track changes to the activated component of the specified outlet.
If the outlet is not rendered (present in the DOM), or hasn't been marked with
Parameters:
Returns:
BehaviorSubject | null
An observable to use for tracking changes to the activated component for the specified outlet, or |
||||||||||
Public instance | ||||||||||
instance(outletName: string)
|
||||||||||
Gets the current instance of the component created by the specified outlet.
Parameters:
Returns:
AnyObject | null
The instance of the component created by the specified outlet. If the outlet doesn't exist, or there is no component instance for the requested outlet, returns |
||||||||||
Public isComponentPublished | ||||||||||
isComponentPublished(outletName: string)
|
||||||||||
Checks whether the outlet by the given name is present in the DOM and has already activated at least one component.
This will be A When
Parameters:
Returns:
boolean
|
||||||||||
Public publishComponent | |||||||||||||||
publishComponent(instance: AnyObject | null, outletName: string)
|
|||||||||||||||
Publishes the instance of a currently activated or deactivated component by the specified outlet.
When an outlet first publishes, this will create an observable for tracking the outlet's changes.
The observable can be fetched using the The last published component of an outlet can be fetched using the
Parameters:
Returns:
void
|
|||||||||||||||
Public unpublishComponent | ||||||||||
unpublishComponent(outletName: string)
|
||||||||||
Notifies any subscribers to the outlet's changes observable that the outlet is being removed by completing the observable and removes the observable from the service.
Parameters:
Returns:
void
|
||||||||||
Public Readonly componentPublished |
Type: EventEmitter<ComponentPublishEventData>
|
Default value: new EventEmitter()
|
Emits whenever a router outlet marked with the |
Public Readonly componentUnpublished |
Type: EventEmitter<RouterOutletEventData>
|
Default value: new EventEmitter()
|
Emits whenever a router outlet marked with the |
outletsState |
getoutletsState()
|
Gets a shallow clone of the current state outlet state.
Returns:
Map<string, AnyObject | null>
|