I am trying to build an application with Angular 6 and I am still setting everything up. But it seems there is something wrong with the dependency injection in my app.
You could try making the below changes:
import {Component} from '@angular/core';
import {TestService} from "./TestService";
@Component({
selector: 'sh-home',
styleUrls: ['./home.scss'],
templateUrl: './home.html',
viewProviders: [TestService]
})
export class HomeComponent {
constructor(private testService: TestService) {
this.testService.sayHello();
}
}
viewProviders creates a special injector that resolves dependencies only for this component.