Angular 6 - can't resolve all parameters for AppComponent

心不动则不痛 提交于 2019-12-03 06:14:33

make sure you have following import in polyfills
import 'core-js/es7/reflect';

I resolved this error by just restarting app. build it again and run it, it's works fine for me. Please check and tell me.

Thanks :)

GET / or compiler error can't resolve all parameters for ApplicationModule: (?).

Just follow these simple steps :

  1. Install core-js modeule.

npm i core-js

  1. In the polyfills.ts file add the import statement

import 'core-js/es7/reflect';

  1. In main.ts file add the import statements

import 'core-js/es6/reflect';

import 'core-js/es7/reflect';

@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();
  }
}

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!