Angular 6 - can't resolve all parameters for AppComponent

前端 未结 10 897
时光取名叫无心
时光取名叫无心 2021-02-07 11:59

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.

10条回答
  •  情歌与酒
    2021-02-07 12:30

    @Inject did the trick for me

    import {Component, Inject} from '@angular/core';
    import {TestService} from "./TestService";
    
    @Component({
      selector: 'sh-home',
      styleUrls: ['./home.scss'],
      templateUrl: './home.html'
    })
    export class HomeComponent {
    
      constructor(@Inject(TestService) testService: TestService) {
        testService.sayHello();
      }
    }
    

提交回复
热议问题