What is the best way to instantiate a service (injectable) with Angular within a class?

import { Store } from '@ngxs/store';
export class Service {

    constructor(private _store: Store) {}
}

export abstract class A {
    constructor( private _service: Service ) {  }
}

export class B extends A {
    constructor( private _service: Service ) {
        super(_service);
    }
}

I want to find a way to prevent classes like B from having to declare and pass the service to A multiple times. I looked into using ReflectiveInjector, but it seems to only work when all providers have the @Injectable() decorator, which the Store does not have.

Does anyone have any ideas on if and how this could be achieved?

Answer №1

To create a new instance of a class, ensure to include the necessary dependencies as shown below:

public database: Database = new Database()    
public server: Server = new Server(this.database);

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Merging two arrays by their corresponding IDs and indexes

Within my current project, I am working with two arrays. The first array, arr1, contains a questionID property that I need to use to combine it with arr2 based on the condition where arr1 questionID equals arr2 index. For example, if arr1 questionID is 1, ...

The ng-click functionality is not functioning as expected within the directive

Take a look at this snippet of my HTML: <section ng-controller="GalleryController as gallery"> <nav footer-directive></nav> </section> This is the GalleryController I'm using: angular .module('myapp') ...

Combine individual websites that have been deployed separately into a single website and display them using a uniform base URL

I have multiple website projects deployed on separate subdomains with their specific resources. I want to create a launch/landing subdomain website that allows users to access each website in different subdomains through the menu, without changing the subd ...

Angular handling multiple query parameters

I am looking to implement multiple path routes for a component named Component2. I want the functionality to be similar to GitHub's file navigation within repositories, but I do not want to hardcode a path like 'source/:filePath/:filePath/:filePa ...

Is there a way to extract a single value from an array of data and convert it into a series of values separated by commas, all using JavaScript but without

Here is an array data in a specific format: const data= [ { name: "productname", id: "1356", price: "0.00", category: "Health", position: "1", list: "New Products", ...

React.js, encountering unusual behavior while implementing a timer

I'm currently working on a React project to create a basic timer. The start button should initialize the timer, while the stop button should pause it. However, I've encountered some unexpected behavior. When I click on start for the first time, ...

What is the best way to synchronously load JSON in JavaScript?

I've encountered an issue while trying to develop an HTML5 game. My goal was to create a modular game by using a JSON file with different modules to load. Here's the code snippet I attempted var resources = {}; $.ajaxSetup({ async: false }); ...

What could be the reason my ImageMapster jquery plugin is not functioning in the Power Apps portal's code editor?

I'm attempting to add hover effects to an image map within my Power Apps portal site using the code editor. However, when I include the script: <script type="text/javascript">$('img').mapster();</script> for the desire ...

Adjusting the outline color of a Material UI Select component in outlined mode to a different color when the dropdown is activated (currently shown as blue)

Is there a way to change the outline color of Material-UI select component outlined variant correctly? I need help changing the default blue color to red, any assistance would be greatly appreciated Click here for an image reference Reference code snippe ...

Tips for capturing and storing video with HTML5 WebRTC

Before reading the description, make sure to run the code snippet first. This will provide you with a better understanding of the structure. In the 2nd video element, I am trying to record, play, and save video. The issue I'm encountering is that the ...

Error: The ng2-scrollreveal package could not be located

When attempting to utilize ng2-scrollreveal npm within my Angular2 application and following all the specified instructions, I encountered console errors: zone.js:1274 GET http://localhost:3000/ng2-scrollreveal 404 (Not Found) and (index):18 Error: Erro ...

Numerous occurrences of Autodesk Forge Viewer

I am facing a challenge in implementing multiple instances of the Autodesk Forge Viewer (v6.2) on my webpage, each hidden within tabs. The goal is to show and hide the viewer with a loaded model as the user switches between tabs. Although I have managed ...

Angular 4 - capturing and resending HTTP requests post-login

My HttpInterceptor is designed to monitor specific JWT token events (token_expired, token_not_provided and token_invalid) that can occur at various stages within the workflow. These events may be triggered when a user switches routes OR when an AJAX reque ...

adjusting the template of the @Component programmatically

The template I am using is generated dynamically based on the intricate rules defined in the Java layer. I am wondering if there is a method to dynamically assign or modify a component's template during ngOnInit or any other suitable point in the cod ...

What could be the reason for the collapse/expansion feature not functioning properly following the addition of

Why isn't my JavaScript code working? It was functioning correctly until I added the next block: <div class="collapse" id="collapse-block"> I have a collapse block (id='collapse-block') which contains 3 other collapse blocks inside. ...

What steps should I take to plan a collaborative code-sharing project?

As I develop various applications utilizing a core framework of my own creation, I am looking for a way to easily manage updates across all these applications. I have structured the code by creating a GitHub project where the main branch consists of the co ...

Is $where in MongoDb optimized for better performance when utilizing functions stored in db.system.js?

MongoDb advises limiting the use of $where due to performance concerns, suggesting to use other operators whenever possible. However, an alternative approach is to store Javascript functions on the server side using the special 'system.js' table. ...

Adding static files to your HTML page with node.js

This is not a question about using express.static() In my application, I have multiple pages that share the same JS and CSS dependencies. Instead of adding <script> or <link> tags to every single page, I'm looking for a way to include the ...

Leveraging Vue.js's capabilities with an external setup file

Is it feasible for a Vue App to access an external configuration file? I envision a setup where I deploy the application along with the config file; then, I should be able to modify the configuration in the external file without needing to rebuild the enti ...

What is the process for integrating php script within javascript?

Is it possible to incorporate php scripts into javascript[1] in the same manner as it can be done in html[2]? server.php: <?php echo 'hello World'; ?> client.js (or client.php if needed): function foo() { var i = <?php include ...