[英]Inheritance with Aurelia
Hi I am using Aurelia with Visual studio 2015. 嗨,我在Visual Studio 2015中使用Aurelia。
I am creating a sports data related site. 我正在创建一个体育数据相关站点。
Here I am having a base class which fetches basic details regarding the sports event. 在这里,我有一个基类,可获取有关体育赛事的基本细节。 I inherit this base class from another class and fetch more information based on the base class property value.
我从另一个类继承了此基类,并根据基类属性值获取了更多信息。
Here is my base class -- 这是我的基础课-
import {inject} from 'aurelia-framework';
import {SportsEventService} from '../services/data-services/sports-event-service.js';
@inject(SportsEventService)
export class BaseClass{
sportsEvent;
constructor(sportsEventService){
this.SportsEventService = sportsEventService;
}
getSportsEventDetail(sportsEventName){
return this.SportsEventService.getSportsEventDetail(sportsEventName)
.then(response => {
this.sportsEvent = response;
return this.sportsEvent;
});
}
}
Here is my child class which inherits base class - 这是继承基类的子类-
import {inject} from 'aurelia-framework';
import {SportsEventService} from '../services/data-services/sports-event-service.js';
import {SportsEvent} from './sports-event'
@inject(SportsEventService)
export class ChildClass extends BaseClass{
constructor(sportsEventService){
super(sportsEventService);
}
getUpcomingFixture(){
return (this.UpcomingFixtureService.getUpcomingFixture(this.sportsEvent.leagueId)
.then(response => {
return response;
}));
}
}
Here, when I am using baseClass property, "this.sportsEvent" it is giving me "Undefine". 在这里,当我使用baseClass属性时,“ this.sportsEvent”给了我“未定义”。 Can anybody tell me, how can I make this work?
谁能告诉我,我该如何做?
this.sportsEvent
will be undefined
until it's assigned at the this.sportsEvent = response;
直到在
this.sportsEvent = response;
分配它之前, this.sportsEvent
undefined
的this.sportsEvent = response;
line. 线。
You won't be able to call the ChildClass.getUpcomingFixture
method until the base class's getSportsEventDetail
method has finished because ChildClass.getUpcomingFixture
depends on this.sportsEvent
. 在基类的
getSportsEventDetail
方法完成之前,您将无法调用ChildClass.getUpcomingFixture
方法,因为ChildClass.getUpcomingFixture
依赖于this.sportsEvent
。
Try executing the code like this: 尝试执行如下代码:
childClass.getSportsEventDetail(sportsEventName)
.then(() => childClass.getUpcomingFixture());
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.