在Lazy加载模块服务中注入服务的问题

时间:2018-02-15 21:57:47

标签: angular lazyload

您好我已经使用LazyService服务创建了延迟加载模块,我想注入我们包含在app模块中的EagerService。之后,当我们运行应用程序时,我看到以下错误。

  

错误错误:未捕获(承诺):错误:无法解决所有问题   LazyService的参数:(?)。        错误:无法解析LazyService的所有参数:(?)

创建了lazyloadservie并包含在

下的lazyload提供程序中

应用程序/懒惰/ lazy.module.ts

...
import { LazyService } from './lazy.service';

@NgModule({
  ...
  providers: [LazyService]
})
export class LazyModule {}

注入了在app load

期间加载的eagerService

应用程序/懒惰/ Lazy.service.ts

import { Injectable } from '@angular/core';
import { EagerService} from '@angular/eager.service';

@Injectable()
export class LazyService{

  constructor(private eagerService: EagerService)
  counter = 0;
  eagerValue = this.eagerService.value;
}

从惰性组件中的lazyservice访问变量

应用程序/懒惰/ lazy.component.ts

import { LazyService} from './lazy.service';

export class LazyComponent {

  constructor(public lazyService: LazyService) {}

  increaseCounter() {
    this.lazyService.counter += 1;
  }
}

在App模块中包含了eagerService

应用程序/ app.module.ts

@NgModule({
  ...
  providers: [EagerService]
})
export class AppModule {}

使用类变量

创建了热切服务

应用程序/ eager.service.ts

export class EagerService{
  constructor()
  value = "vale from eager service";
}

请帮我解决这个问题。

0 个答案:

没有答案