service代码如下
import { Injectable } from '@angular/core';
import { FatherModule } from './father/father.module'
@Injectable({
providedIn: FatherModule
})
export class InnerService {
constructor() { }
sayHello(){
console.log('good morning')
}
}
father.module.ts代码如下
import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { FatherComponent } from './father.component'
import { SonComponent } from '../son/son.component'
@NgModule({
declarations: [
SonComponent
],
imports: [
CommonModule
],
providers:[]
})
export class FatherModule { }
出现了如下错误
StaticInjectorError(Platform: core)[FatherComponent -> InnerService]:
NullInjectorError: No provider for InnerService!
at
没有把module放入appModule的import中