我有一个项目,在该项目中,我有一组相互延伸的组件,并从子对象继承父对象的属性([基类]证书-> [抽象类]应用程序-> [继承的底部] Individual_Types)。一切正常,但底部组件包含多个嵌套组件,我想与嵌套组件共享一些继承的属性。
如果我尝试在属性绑定中使用那些继承的变量之一,则会收到错误消息“错误TypeError:无法读取未定义的属性'Id'”。但是,如果我改为在personal_type组件中设置一个成员变量并将其设置为构造函数中的继承属性,则可以在绑定中使用该成员变量而不会出错。
在“应用程序”组件中:
export abstract class ApplicationComponent extends CertificationComponent implements OnInit {
protected BaseAppType: AppType;
protected BaseAppId: string;
// Injected Services
protected AppRouter: Router;
protected AppServ: ApplicationService;
constructor(private AppInject: Injector,
private AppCertId: string,
private AppTypeId: string,
private AppSumId: number) {
super(AppInject, AppCertId);
this.AppRouter = AppInject.get(Router);
this.AppServ = AppInject.get(ApplicationService);
// Default AppType - BaseAppType actually set in ngOnInit
this.BaseAppType = new AppType();
}
继承底例:
export class NewBcabaComponent extends ApplicationComponent implements OnInit {
private ParentAppType: AppType;
public constructor(NewInject: Injector) {
super(NewInject, '2', '1', 11);
this.ParentAppType = this.BaseAppType;
}
带有嵌套组件的示例模板
这有效:
<div class="open-card-BG" *ngIf="CurrentPage == 1">
<instructions [InstAppType]="ParentAppType"></instructions>
</div>
这不是:
<div class="open-card-BG" *ngIf="CurrentPage == 1">
<instructions [InstAppType]="BaseAppType"></instructions>
</div>