Questions tagged [injectable]

121 questions
19
votes
4 answers

Unit testing with private service injected using jasmine angular2

I have a problem trying to unit test an angular service. I want to verify that this service is properly calling another service that is injected into it. Lets say I have this ServiceToTest that injects ServiceInjected: ServiceToTest…
RjHiruma
  • 193
  • 1
  • 1
  • 4
15
votes
3 answers

Angular 6: provide HTTP_INTERCEPTORS for 'root'

With the change from Angular 5 where you provide service in AppModule to Angular 6 where you set 'provideIn' key in @Injectable decorator I have changed all services to use new "provideIn" method. However, exception is my Interceptor Service. How…
Miloš Tomšik
  • 225
  • 1
  • 3
  • 9
15
votes
2 answers

What is the difference between @Inject and @Injectable in Angular 2 typescript

I don't understand When to use @Inject and when to use @Injectable ? import {Component, Inject, provide} from '@angular/core'; import {Hamburger} from '../services/hamburger'; export class App { bunType: string; …
Sarvesh Yadav
  • 2,600
  • 7
  • 23
  • 40
10
votes
2 answers

How should I extend Injectable from another Injectable with many Injections in angular2?

Is it possible to do something like this? (cause I tried, and haven't succeed): @Injectable() class A { constructor(private http: Http){ // <-- Injection in root class } foo(){ this.http.get()... }; } @Injectable() class B…
karina
  • 789
  • 9
  • 26
9
votes
2 answers

How Use shared preference with injectable and get_it in flutter?

im using injectable and get_it package in flutter i have a shared preference class : @LazySingleton() class SharedPref { final String _token = 'token'; SharedPreferences _pref; SharedPref(this._pref); Future getToken() async { …
8
votes
1 answer

Dependency Injection, injecting an "injectable" object (service) into a newable (entity)

When writing code we should be able to identify two big group of objects: Injectables Newables http://www.loosecouplings.com/2011/01/how-to-write-testable-code-overview.html http://misko.hevery.com/2008/09/30/to-new-or-not-to-new/ Injectable…
8
votes
0 answers

Proper way of using DI (injectable-getIt) for testing in flutter?

Is it fine to get instances from getIt initialised in lib(dev) code or should I use another way, or another DI setup for tests? Please refer the code below: void main() { TravellerProfileViewModel travellerProfileViewModel; UserService…
7
votes
0 answers

Using Angular 8 Injectable service inside Web Worker

I have an Angular application which initialises Web Worker and starts some rendering operations inside it. Worker has instance of helper class Renderer to perform rendering operations. Now I need to get real time data from RealtimeDataService…
Michael
  • 151
  • 1
  • 8
7
votes
3 answers

Dependency injection when the class created also needs runtime values?

Assume you divide up your systems in Value objects and Services objects (as suggested in "Growing Object-Oriented Software, Guided by Tests". Misko Hevery calls these "newables" and "injectables". What happens when one of your value objects…
WW.
  • 23,793
  • 13
  • 94
  • 121
6
votes
2 answers

Is there a way to pass factory params?

I have something like that: @injectable class SettingsBloc { final Event event; SettingsBloc(@factoryParam this.event); } When I call it from my code, I pass factory param like: getIt(param1: Event()) But when SettingsBloc is…
Alexander Farkas
  • 529
  • 3
  • 11
6
votes
2 answers

How do I get an instance of Angular router without injecting it?

Usually I'd go like this in my component. import { Router } from "@angular/router"; @Component({ ... }) export class CompyTheComponent { constructor(private router: Router) { console.log(router.url); } } What if I want to obtain a…
Konrad Viltersten
  • 36,151
  • 76
  • 250
  • 438
6
votes
1 answer

How to make Angular2 Service singleton?

I'm trying to implement an auth guard in my app. ie; Only authenticated users can access certain routes of my app. I'm following the tut given here. Once the user is logged in I change a boolean value in my AuthService to true to indicate that the…
Rahmathullah M
  • 2,676
  • 2
  • 27
  • 44
5
votes
1 answer

Accessing service from exported function in a module declaration in Angular 2+

I have the following Module declaration: import { ConnectionService } from './services/connection.service'; import { NgModule } from '@angular/core'; import { Http, RequestOptions } from '@angular/http'; import { AuthHttp, AuthConfig } from…
jufracaqui
  • 234
  • 4
  • 15
5
votes
2 answers

Angular2 routed component interaction with parent

Please consider the bellow diagram for my application EventsHub is a simple injectable service : import {Injectable} from '@angular/core'; import {Subject} from 'rxjs/Subject'; @Injectable() export class EventsHub { private…
Hasan
  • 1,814
  • 1
  • 12
  • 14
4
votes
0 answers

Flutter Injectable: inject multiple instances of generic types via annotation

I am using get_it in my flutter project for the dependency injection. Now I am trying to do it with injectable to replace my handwritten dependency file with annotations. I have the special case, that I have a class which is generic and must be…
A.K.
  • 568
  • 5
  • 17
1
2 3
8 9