In my development workflow, I have established an Angular Component Library that I deploy using NPM (via Nexus) to various similar projects. This library includes a PageComponent
, which contains a FooterComponent
and a NavbarComponent
. Within the NavbarComponent
, there is a button that triggers a function called logout
. To enable this functionality, the function must be provided through a PageService
specific to each project. For this purpose, I introduced an AbstractPageService
within the Angular Component Library (PageService
extends AbstractPageService
).
Initially, I addressed this requirement by using an EventEmitter
. However, as it necessitated providing a separate logout
function for every new page, I sought a more efficient solution employing a single service per project. I achieved this by passing the respective PageService
(for each project) using the forRoot()
method of the Angular Component Library.
Although everything functions as intended, I am curious to explore whether there might be a more optimal approach or if this current solution suffices?
Below is the implementation of this solution:
Components Lib - components.module.ts
// Inserted code for ComponentsModule
Component Lib - page.component.ts
// Inserted code for PageComponent
Component Lib - abstract-page.service.ts
// Inserted code for AbstractPageService
Utilization within a project is demonstrated below:
Project - app.module.ts
// Inserted code for AppModule
Project - page.service.ts
// Inserted code for PageService