如何使用直接注入扩展 class
How do I extend a class thats using direct injection
希望这对你们中的一些人来说应该是一个相对简单的问题...
我正在尝试扩展一个组件,但我不确定如何处理新组件的构造方法。
下面是我的基础组件
import { Component, OnInit } from '@angular/core';
import { ControlsService } from '../controls.service'
@Component({
moduleId : module.id,
selector : 'app-base',
templateUrl : 'base.component.html',
styleUrls : ['base.component.css'],
providers : [ControlsService]
})
export class BaseComponent implements OnInit {
constructor(_controlService:ControlsService) {}
ngOnInit() {
// console.log(this._controlService.getControlByID('B5EE385D-1D6A-335A-1E94-2F857428A6FB'))
}
}
下面是我的新组件
import { Component, OnInit } from '@angular/core';
import { MdToolbar } from '@angular2-material/toolbar';
import { MdIcon, MdIconRegistry} from '@angular2-material/icon';
import { PanelComponent } from '../panel/panel.component'
import { BaseComponent } from '../base/base.component'
import { ControlsService } from '../controls.service'
@Component({
moduleId : module.id,
selector : 'app-workbench',
templateUrl : 'workbench.component.html',
styleUrls : ['workbench.component.css'],
directives : [MdToolbar,MdIcon,PanelComponent],
providers : [MdIconRegistrym,ControlsService]
})
export class WorkbenchComponent extends BaseComponent implements OnInit{
workbenchTitle = "Selection Category "
constructor(_controlService:ControlsService)
{
super(this._controlService)
}
ngOnInit() {
}
}
我需要我的 _controlService 位于基础组件中,因为该服务将检索控件参数,但似乎如果我在基础组件构造函数方法中创建服务,则必须将其传递到基础组件中来自新组件。我宁愿不这样做,但似乎我可能不得不这样做。
返回给我的错误是:
(17, 21): 提供的参数与调用目标的任何签名都不匹配。
有人能为我指明正确的方向,告诉我如何正确扩展这个基本组件。
谢谢!
this.
无效
export class WorkbenchComponent extends BaseComponent implements OnInit{
constructor(_controlService:ControlsService)
{
// super(this._controlService)
// should be
super(_controlService)
}
}
希望这对你们中的一些人来说应该是一个相对简单的问题...
我正在尝试扩展一个组件,但我不确定如何处理新组件的构造方法。
下面是我的基础组件
import { Component, OnInit } from '@angular/core';
import { ControlsService } from '../controls.service'
@Component({
moduleId : module.id,
selector : 'app-base',
templateUrl : 'base.component.html',
styleUrls : ['base.component.css'],
providers : [ControlsService]
})
export class BaseComponent implements OnInit {
constructor(_controlService:ControlsService) {}
ngOnInit() {
// console.log(this._controlService.getControlByID('B5EE385D-1D6A-335A-1E94-2F857428A6FB'))
}
}
下面是我的新组件
import { Component, OnInit } from '@angular/core';
import { MdToolbar } from '@angular2-material/toolbar';
import { MdIcon, MdIconRegistry} from '@angular2-material/icon';
import { PanelComponent } from '../panel/panel.component'
import { BaseComponent } from '../base/base.component'
import { ControlsService } from '../controls.service'
@Component({
moduleId : module.id,
selector : 'app-workbench',
templateUrl : 'workbench.component.html',
styleUrls : ['workbench.component.css'],
directives : [MdToolbar,MdIcon,PanelComponent],
providers : [MdIconRegistrym,ControlsService]
})
export class WorkbenchComponent extends BaseComponent implements OnInit{
workbenchTitle = "Selection Category "
constructor(_controlService:ControlsService)
{
super(this._controlService)
}
ngOnInit() {
}
}
我需要我的 _controlService 位于基础组件中,因为该服务将检索控件参数,但似乎如果我在基础组件构造函数方法中创建服务,则必须将其传递到基础组件中来自新组件。我宁愿不这样做,但似乎我可能不得不这样做。
返回给我的错误是: (17, 21): 提供的参数与调用目标的任何签名都不匹配。
有人能为我指明正确的方向,告诉我如何正确扩展这个基本组件。
谢谢!
this.
无效
export class WorkbenchComponent extends BaseComponent implements OnInit{
constructor(_controlService:ControlsService)
{
// super(this._controlService)
// should be
super(_controlService)
}
}