以下是我的code:
export class RosterTableComponent implements OnInit {
rosterRule: RosterRule
constructor(private calendarService: CalendarService,private rosterService: RosterService) {
this.rosterService.getRosterRule().subscribe((res: RosterRule) => {
this.rosterRule=res;
this.rosterRule.add(); // <==問題出在這裡
});
}
因為這個RosterRule Object 本身有自己的method(e.g. add), 可是當我call this.rosterRule.add 時,browser 就說沒有add這個method, 請問為什麼呢?
暫時我用以下方法去解決:
this.rosterService.getRosterRule().subscribe((res: RosterRule) => {
this.rosterRule = new RosterRule();
this.rosterRule.essentialShiftList = res.essentialShiftList;
this.rosterRule.maxConsecutiveWorkingDay = res.maxConsecutiveWorkingDay;
this.rosterRule.shiftHourCount = res.shiftHourCount;
this.rosterRule.shiftTimeSlot = res.shiftTimeSlot;
this.rosterRule.shiftCssClassName = res.shiftCssClassName;
this.rosterRule.add(); //<=這樣就沒問題了
});