The Author Online Book Forums are Moving

The Author Online Book Forums will soon redirect to Manning's liveBook and liveVideo. All book forum content will migrate to liveBook's discussion forum and all video forum content will migrate to liveVideo. Log in to liveBook or liveVideo with your Manning credentials to join the discussion!

Thank you for your engagement in the AoF over the years! We look forward to offering you a more enhanced forum experience.

291209 (3) [Avatar] Offline
#1
Has anybody else encountered a StaticInjectorError after inserting the code from Chapter 6 section 6.7? I have doubled checked everything, compared against the github repo, and the only thing that seems to work is to remove the additional code added to the app from 6.7. I've attached an image of the error I'm receiving.

This is what I have in my app.component.ts file:

import { Component, OnInit, OnDestroy } from '@angular/core';
import { AccountService } from './services/account.service';
import { Stock } from './services/stocks.model';
import { StocksService } from './services/stocks.service';

@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css'],
providers: [
StocksService
]
})
export class AppComponent implements OnInit, OnDestroy {
refresh: boolean = true;
stocks: Stock[] = [];
interval: any;

constructor(private accountService: AccountService, private stocksService: StocksService) { }

ngOnInit(): void {
this.load();

this.interval = setInterval(() => {
if (this.refresh) {
this.load();
}
}, 15000);
}

ngOnDestroy(): void {
clearInterval(this.interval);
}

toggleRefresh(): void {
this.refresh = !this.refresh;
}

reset(): void {
this.accountService.reset();
}

private load(): void {
this.stocksService.getStocks().subscribe(stocks => {
this.stocks = stocks;
}, error => {
console.error(`There was an error loading stocks: ${error}`);
});
}
}
jeremy.wilken (208) [Avatar] Offline
#2
The error indicates that the HttpClient is not found, which means that the HttpClientModule must not be imported into your app module correctly. See here to make sure you have this line

https://github.com/angular-in-action/portfolio/blob/master/src/app/app.module.ts#L29
291209 (3) [Avatar] Offline
#3
jeremy.wilken wrote:The error indicates that the HttpClient is not found, which means that the HttpClientModule must not be imported into your app module correctly. See here to make sure you have this line

https://github.com/angular-in-action/portfolio/blob/master/src/app/app.module.ts#L29


That did the trick! Thanks for your help and quick reply!