Questions tagged [angular2-injection]
45 questions
1
vote
1 answer
Is there any reason(except unit-tests) to use Angular2 Dependancy Injection?
I'm trying to figure out why we need Angular2 Dependancy Injection.
Case with tests is clear: we could easily mock any Service.
But could you provide any other reason?

Stepan Suvorov
- 25,118
- 26
- 108
- 176
1
vote
2 answers
Angular 2 injector can't find Service when loading CustomExceptionHandler
When trying to inject a service into my CustomExceptionHandler, the Angular injector cannot find the service.
The error: Uncaught Can't resolve all parameters for CustomExceptionHandler: (?).
The setup:
CustomExceptionHandler
import {…

Daniel Patrick
- 3,980
- 6
- 29
- 49
1
vote
1 answer
Angular: parent and child component communication, @Host and forwardRef
I am experimenting with the newly released Angular beta 0 and hoping someone can clarify some things for me.
I have an AppComponent which is serving as the main framework of my project. Its template creates a navigation bar, the items of which are…

trance_dude
- 91
- 1
- 7
0
votes
1 answer
Angular 2 component inject service: "[ts] Property doesn't exist on the type"
I am noob in Angular 2. I am developing a simple app.
I have a problem when I use a service in a Angular 2 app.
When I want use it on a component, I can't use the getFavoritos() service method on ngOnInit() component method.
Node console shows…

Jatienza
- 1
- 4
0
votes
1 answer
`ng serve` fails if service is not provided directly in component
I have a project structured like so:
project
-src
--app
---project
----project.component.ts
----project.component.html
----project.component.sass
---project.module.ts
---project.service.ts
From within my component I am attempting to use the…

Jeremy
- 3,620
- 9
- 43
- 75
0
votes
1 answer
Separate Files for Functions in Angular 2/4 Injectable
I'm writing a service which is likely going to grow exponentially, and I would like to be able to write separate files and load them into an @Injectable that a component uses. Normally I would just write multiple services and inject each one into…

Z. Bagley
- 8,942
- 1
- 40
- 52
0
votes
1 answer
Angular 2 custom pipe with Dependency Injection
Say I create a pipe like so:
import { Pipe, PipeTransform } from '@angular/core';
import { CurrencyPipe } from '@angular/common';
@Pipe({
name: 'awesomePipe'
})
export class AwesomePipe implements PipeTransform {
constructor(private currency:…

Abraham P
- 15,029
- 13
- 58
- 126
0
votes
1 answer
Angular2 Communication Between Components
I search about communication between components with Angular2 i try in this mode but doesn t work
the template variantpages.component.html content this
@Component({
selector:…

corsaro
- 731
- 1
- 9
- 24
0
votes
0 answers
How to add injection when I overwrite provider with parameters in constructor?
I'm overwriting RequestOptions for my application by doing something like:
export class RequestOptionsService extends RequestOptions {
...
}
and after:
{ provide: RequestOptions, useClass: RequestOptionsService },
Now I would like to inject…

Stepan Suvorov
- 25,118
- 26
- 108
- 176
0
votes
3 answers
Angular2 Inject Http Without Bootstrap
Context:
I have a class that is going to form POST requests for my REST Api, lets call it requester. Every ajax call made in my app will be sent through this. Thus I don't want to provide Http via bootstrap(foo, [HTTP_PROVIDERS]); That would make it…

ZaksBack
- 189
- 3
- 10
0
votes
1 answer
Angular 2: How to inject simple types into your service
I have a basic service that has a single string parameter
import {Injectable} from 'angular2/core';
@Injectable()
export class MyService {
constructor(someValue: string) {
}
}
If I remove the string param from the constructor the service…

Dan Soltesz
- 898
- 1
- 9
- 16
0
votes
2 answers
Angular2, Injecting contants
I am doing like this:
import {testInjection} from './ts/models';
import {bootstrap} from 'angular2/platform/browser';
bootstrap(AppComponent, [testInjection]).catch(err => console.error(err));
in models.ts
let TEST:string = "test";
export var…

Miha Zoubek
- 65
- 10
0
votes
0 answers
Angular2 have a way of injecting into the current Injector without creating child
I'm looking for a way to manipulate the current components Injector. I know that I can use :
constructor(private injector: Injector) { }
to get the injector, but there are no methods exposed on it that allow me to append services to the current…

studiollama
- 11
-1
votes
1 answer
DI error in subcomponent
I'm developing a (really) huge Angular 2 application as an internal tool for my company. The application is made up of different sub-applications, that can be accessed only by certain users.
In order to do this, I tried using a CanActivate class…

Isaia Maccali
- 9
- 2
-1
votes
2 answers
Where to put service providers in angular 2 hierarchy so that components can talk to each other using the same instance of service?
Related question:
Observable do not receive the next value in angular2
No provider for service error in angular2, why do I need to inject it in it's parent component?
Using observable talk to other component in angular2, not receiving coming…

Xinrui Ma
- 2,065
- 5
- 30
- 52