나는이 작업을 수행 할 수 있습니다 대신의각도 2 : 대신 생성자 주입의 속성 주입
export class BaseComponent {
protected config: IConfig;
@Inject(AppConfig) protected appConfig: AppConfig;
constructor()
{
this.config = this.appConfig.getConfig();
}
:
export class BaseComponent {
config: IConfig;
constructor(
private appConfig: AppConfig,
)
{
this.config = appConfig.getConfig();
}
목표는 생성자 서명을 단순화하기 위해, 그래서 모든 하위 구성 요소를하지에 생성자에 appConfig를 지정해야합니다. 그래서 BaseComponent에서 상속 구성 요소는 다음과 같다 없습니다 :
@Component({
selector: 'sport-templates',
templateUrl: 'templates.component.html',
styleUrls: [ 'templates.component.scss' ],
encapsulation: ViewEncapsulation.None
})
export class SportTemplates extends BaseComponent implements OnInit {
constructor() {
super();
}
를 대신 다음과 같이 :
@Component({
selector: 'sport-templates',
templateUrl: 'templates.component.html',
styleUrls: [ 'templates.component.scss' ],
encapsulation: ViewEncapsulation.None
})
export class SportTemplates extends BaseComponent implements OnInit {
constructor(appConfig: AppConfig) {
super(appConfig);
}
@ 각도/코어입니까? – PaladiN
내 질문에 대한 답변을 찾았습니다. https://stackoverflow.com/questions/42461852/angular-2-inject-service-manually Thanks. –