In general, I have a service:

import { Injectable } from '@angular/core'; import { HttpClient } from '@angular/common/http'; import { Observable } from 'rxjs'; import { Bill } from '../models/bill.model'; @Injectable export class BillService { constructor(private http: HttpClient) {} getBill(): Observable<Bill> { return this.http.get('http://localhost:3000/bill'); } getCurretncy(): Observable<any> { return this.http.get(`http://data.fixer.io/api/latest?access_key=${this.apiKey}&symbols=RUB,USD,EUR`); } } 

And I make calls to these functions like this:

 export class BillPageComponent implements OnInit, OnDestroy { subscription: Subscription; constructor(private billService: BillService) { } ngOnInit() { this.subscription = combineLatest(this.billService.getBill(), this.billService.getCurretncy()).subscribe((data: [Bill, any]) => { console.log(data); }); } ngOnDestroy() { this.subscription.unsubscribe(); } } 

Well, in general, I catch this error on @Injectable :

 Argument of type 'typeof BillService' is not assignable to parameter of type '({ providedIn: Type<any> | "root"; } & ValueSansProvider) | ({ providedIn: Type<any> | "root"; } & ExistingSansProvider) | ({ providedIn: Type<any> | "root"; } & StaticClassSansProvider) | ({ ...; } & ConstructorSansProvider) | ({ ...; } & FactorySansProvider) | ({ ...; } & ClassSansProvider)'.   Type 'typeof BillService' is not assignable to type '{ providedIn: Type<any> | "root"; } & ClassSansProvider'.     Type 'typeof BillService' is not assignable to type '{ providedIn: Type<any> | "root"; }'.       Property 'providedIn' is missing in type 'typeof BillService'. 

In general, I ask for help in order to understand this chaos.

  • @Injectable() is a factory, please read the documentation for DI in Angular, it is described on the first pages - overthesanity
  • besides, why are you thrusting http streams into combinelatest + combinelatest into a subscription, these streams close automatically after generating a response event .... - overthesanity
  • Well, at the moment I am learning video tutorials, and these are the lessons from angular4, that's all - Moonwolf45

1 answer 1

Before

 @Injectable 

After

 @Injectable({ providedIn: 'root' })