【问题标题】:Angular 5 : How to pass classname in providersAngular 5:如何在提供者中传递类名
【发布时间】:2018-07-19 11:57:06
【问题描述】:

我想在提供者内部传递一个类名,如下所示:

@Component({
  selector: 'home',
  templateUrl: 'home.component.html',
  providers: [Logger('HomeComponent')] <--- class name here
})

export class HomeComponent implements OnInit {

}

可以这样做吗?

【问题讨论】:

  • 这甚至没有意义。你将如何使用它?
  • 您的具体要求是什么。 Provider 用于手动设置输入依赖解析,而不是让 Angular 决定解析的项目。
  • 我想命名使用这个提供者的类

标签: angular


【解决方案1】:

看起来你想提供一个服务类 -

export class HomeComponent {


  constructor(public logger: NGXLogger) {
  }
}

@Component({
  selector: 'app-Home',
  providers: [ NGXLogger ]
)}

【讨论】:

    猜你喜欢
    • 2021-11-06
    • 1970-01-01
    • 2018-07-30
    • 2018-11-17
    • 2018-08-04
    • 2018-06-21
    • 2018-08-10
    • 2019-12-27
    • 2020-12-21
    相关资源
    最近更新 更多