Questions tagged [angular-dependency-injection]

Use this tag if your question is specially about the behavior of the angular dependency injection framework.

Dependency injection (DI), is an important application design pattern. Angular has its own DI framework, which is typically used in the design of Angular applications to increase their efficiency and modularity.

Dependencies are services or objects that a class needs to perform its function. DI is a coding pattern in which a class asks for dependencies from external sources rather than creating them itself.

In Angular, the DI framework provides declared dependencies to a class when that class is instantiated. This guide explains how DI works in Angular, and how you use it to make your apps flexible, efficient, and robust, as well as testable and maintainable.

For more information about angular DI visit the official documentation

107 questions
0
votes
1 answer

I created My angular project in Angular v8.1.3 , I want to run all the above angular version

I am trying to update my Angular app from v5 to v6 following. I have ran all these commands successfully: npm install -g @angular/cli npm install @angular/cli ng update @angular/cli The problem is that I get an error when running this command: ng…
0
votes
2 answers

Angular, Unable to find the root parent by its class interface

From the angular documentation here, I had created a Parent class using export abstract class Parent {} Inside the AlexComponent, I had provided this component as Parent to its children providers: [{ provide: Parent, useExisting: forwardRef(() =>…
0
votes
2 answers

How to use a variable from a component in another in Angular

I have two component. alert-component and master component. Now I want to use master-component variable into alert component. But without import it because in master-component I have already import alert-component. And again if I try to import…
0
votes
1 answer

Angular: remove providers injected from module in the component providers declaration

I have declaration of providers in app module which provides list of implementations of MyProviderService class (I am using multi: true). Now I would like to "undefine" this list in one component completely, so I added: @Component({ providers: [ …
sax
  • 808
  • 1
  • 12
  • 25
0
votes
1 answer

How to make a string dependency token accessible to components?

I'm building an Angular app that uses Angular universal for server-side rendering. I got a string dependency token being passed as a provider in the providers array of server.ts providers: [{ provide: 'MODEL', useValue: process.env.API_MODEL }] The…
0
votes
1 answer

Angularjs different dependency injection for factories inside controller

Say I have multiple factories and these factories have same functions and variables inside. For example, var app = angular.module('app', []); app.factory('employerFactory', function () { return { firstName: 'Kristoffer', …
0
votes
1 answer

Angular: Using the providers array of a component imported from a different module

I have a ViewerWidgetComponent - selector app-viewer-widget, declared in and exported from SharedModule. The ViewerWidgetComponent has a child component from a third party library: AcMapComponent - selector ac-map, where content is projected within…
0
votes
1 answer

Why is module constructor only called once?

Suppose I have three modules: App module Core module SomeFeature module Then I import both Core and SomeFeature modules in App Module import Core module in SomeFeature module add console.log('hello') to constructor of Core module Why 'hello' is…
0
votes
1 answer

Angular 13: What is wrong with my HTTP Get Request?

I've tried many formats and feel like I am almost there. I have no idea what is wrong with this get request. I've been following tutorials via Pluralsight and have followed exactly what they're doing. No luck either way. Please provide some…
0
votes
1 answer

Call service method to provide other services within app.module.ts

I have a configuration service that provides a method called getConfiguration(): Observable . In order to fill my external library, I would like to provide this method within app.module.ts (I want to fill the InjectionToken, which is…
EchtFettigerKeks
  • 1,692
  • 1
  • 18
  • 33
0
votes
1 answer

Angular programmatic navigation - Why router does not in providers array

In Angular Dependency Injector when ever we injecting a Type , we will includes them in providers array (May be in @NgModule decorator or @Component decorator. But in the following instance when we navigate programmatically we inject Router instance…
0
votes
0 answers

deep-equal 2.0.5 lib integration with Angular 10

I'm trying to integrate latest version of deep-equal with angular application (v10). I added deep-equal version 2.0.5 as "dependency" in package.json (Assuming if this library is dependant on other libs, npm will auto download required…
0
votes
0 answers

Using Injected Token to configure a lazily loaded module

Consider the following snippet. How do I access the provided value of Environment in forRoot? Is there an alternate way that I do the same? interface Environment { tokens: Record; } const ENVIRONMENT = new…
0
votes
1 answer

Data from the service not available when accessed from the same level to app in Angular

I have a problem related to dependency injection. I am new to Angular, the problem is that, I tried to store the logged-in user data in service and call this service in the app component that gets logged in user information from API. The data from…
0
votes
1 answer

How to provide an implementation for a given class using DI in Angular?

Consider that I have 2 modules called A and B. Let's say I have this class. It doesn't really "belong" to any module since it's a plain old Typescript class rather than an Injectable. class Greeter { constructor(private greeting: string) {} …
Allan Juan
  • 2,048
  • 1
  • 18
  • 42