我正在研究Angular 2,并希望找到已知类型的父组件。但得到了这个错误:
错误:(SystemJS)Base未定义。
ReferenceError:未定义Base
请说明我做错了什么。
parent-finder.component.ts:
import { Component, OnInit } from '@angular/core';
import { Router } from '@angular/router';
@Component({
selector: 'alex',
template: `
<div class="a">
<h3>{{name}}</h3>
<cathy></cathy>
<craig></craig>
</div>`,
})
export class AlexComponent extends Base
{
name= 'Alex';
}
@Component({
selector: 'cathy',
template: `
<div class="c">
<h3>Cathy</h3>
{{alex ? 'Found' : 'Did not find'}} Alex via the component class.<br>
</div>`
})
export class CathyComponent {
constructor( @Optional() public alex: AlexComponent ) { }
}
@Component({
selector: 'craig',
template: `
<div class="c">
<h3>Craig</h3>
{{alex ? 'Found' : 'Did not find'}} Alex via the base class.
</div>`
})
export class CraigComponent {
constructor( @Optional() public alex: Base ) { }
}
答案 0 :(得分:0)
得到答案,应该添加基类和父类。
export abstract class Base { name = 'Count Basie'; }
export abstract class Parent { name: string; }