Linked Questions
12 questions linked to/from How to inject service into class (not component)
2
votes
2
answers
5k
views
Getting dependency from Injector manually inside a directive
I am trying to create a generic directive which will take a class type for rule validation and according to the rule in the class the directive will either show or hide an element.
This is my ...
3
votes
2
answers
4k
views
Use service in class with Angular 2
I would like to use a service in my class (model)
Use Service in my Class
movie-list.component.ts
import { Component, OnInit } from '@angular/core';
import {Movie} from "../../models/movie";
import ...
2
votes
1
answer
1k
views
How to inject a service into a class that must be instantiated in app module in angular 7?
I am using ngxs in a project and I want to use the ngxs logger plugin, but I want to override the logger itself so that I am able to log to the backend. For this I need to inject my RestService in my ...
1
vote
1
answer
736
views
Is possible to get the Instance of an Angular Service outside an angular component?
Is possible to get the instance reference of a Injectable angular service in a generic class?
I need to not put the angular Injectable in the constructor, so I am trying to find a different approach ...
0
votes
0
answers
839
views
Angular 4 Dependency Injection for "model" classes
I am build an Angular 4 app in which I am trying to use "model" classes like the following:
export interface UserI {
uid?: string;
birthdate: number;
firstname: string;
}
export class User ...
3
votes
1
answer
668
views
Why is my service undefined?
I am trying to inject a service into one of my classes but I am not able to use it as it is 'undefined'.
symbolPicker.ts
import {EditorService} from './editor.service';
import * as ...
1
vote
1
answer
536
views
When should I DI the Injector directly in an Angular app?
By directly I mean like this:
constructor(private injector:Injector) {
injector.get(MyService);
}
Currently I am using this syntax on base classes that require many dependencies in order to add to ...
0
votes
1
answer
670
views
Injecting service in the class / pure functions
I am working on Angular project (Angular 14+) and following atomic design principles (creating minute level components like button, input, toggle etc.).
Most of the views (list, forms, headers) are ...
1
vote
1
answer
630
views
Angular: DI in inherited component from abstract base
So in my Angular project, I was trying to have an abstract base class for editing forms. Let's call it Editor.
There will be many components that do operations on a form so they inherit from the base ...
0
votes
0
answers
426
views
Send data from TS class to Angular component via service
Outside of Angular project, there is a TS class from which I'm trying to send object to angular component via service.
sender.ts is TS class which sends object using Angular service;
export class ...
0
votes
1
answer
46
views
Use classes in component and dependency injection
I use Angular and have 1 component, 1 class and 1 service.
My service is an @injectable class and well setted in app.module.ts.
@Injectable()
export class MyService {
My class get the service as an ...
0
votes
0
answers
47
views
APP_INITIALIZER - How to access enviroment properties in all classes?
I am using the APP_INITIALIZER with useFactory for the configuration file to load environment properties as json file during the run time. It works and I can access the properties in different ...