我从这里https://github.com/mattlewis92/angular-calendar#getting-started使用Angular日历。
当我单击一天时,我希望将其保存在数据库中。 我已经完成了BE和FE这两个部分的工作,但是我对这个特定的组件有疑问。
这是我的代码:
month-calendar.component.ts(子组件)
export class MonthCalendarComponent implements OnInit {
@ViewChild('modalContent') modalContent: TemplateRef<any>;
view = 'month';
@Input() holidayClicked: Function;
dayClicked(day: CalendarMonthViewDay): void {
const sub = this.holidayClicked(day);
console.log(sub);
sub.subscribe(isHoliday => {
if (isHoliday) {
delete day.cssClass;
} else {
day.cssClass = 'cal-day-selected';
}
});
}
calendar-component.ts(父组件)
@Component({
selector: 'ca-calendar',
templateUrl: './calendar.component.html',
styleUrls: ['./calendar.component.css']
})
export class CalendarComponent implements OnInit {
@ViewChildren(MonthCalendarComponent) months: any[];
holidayClicked = function (day: CalendarMonthViewDay): Observable<boolean> {
const username = 'dinchmle';
const holiday = new Holiday();
holiday.date = day.date;
holiday.stateVal = this.stateSelected;
holiday.comment = '';
return this.calendarService.updateEmployee(username, holiday).map(
response => {
if (holiday && holiday.stateVal !== 1) {
return true;
} else {
return false;
}
});
};
holiday.ts
import { eState } from './eState';
export class Holiday {
date: Date;
stateVal: eState;
comment: string;
isSelected: boolean;
constructor() {
}
}
...和calendar.service.ts
updateEmployee(userName: string, holiday: Holiday): Observable<Holiday> {
const url = this._employeeUrl + '/holiday?userName=' + userName;
return this.http.put(url, holiday)
.map((res: Holiday) => res)
.catch(this.handleError);
}
问题在这里
holiday.date = day.date;
day.date未定义。
我做错什么了吗,或者是我使用的日历组件中的错误?