我正在使用引导程序4和angular 6和igx-calendar来创建一个简单的预订表单,表单如下。igx-calendar
HTML。
<form [formGroup]="angForm" class="form-element">
<div class="col-sm-4 offset-sm-2 about-booking_calendar">
<div class="form-group form-element_date">
<app-calendar formControlName="date" #date></app-calendar>
</div>
</div>
<div class="col-sm-4 about-booking_form">
<div class="form-group form-element_email">
<input type="email" class="form-control info" placeholder="Email" formControlName="email" #email (ngModelChange)="onChange($event)">
</div>
<div *ngIf="angForm.controls['email'].invalid && (angForm.controls['email'].dirty || angForm.controls['email'].touched)"
class="alert alert-danger">
<div *ngIf="angForm.controls['email'].errors.required">
Email is required.
</div>
</div>
<div class="input-group mb-3 form-element_city">
<select class="custom-select" id="inputGroupSelect01" #cityName>
<option selected *ngFor="let city of cities" [ngValue]="city.name">{{city.name}}</option>
</select>
</div>
<div class="input-group mb-3 form-element_hotel">
<select class="custom-select" id="inputGroupSelect01" #hotelName>
<option selected *ngFor="let hotel of hotels" [ngValue]="hotel.name">{{hotel.name}}</option>
</select>
</div>
<div class="form-group">
<button type="submit" (click)="addReview(date.value, email.value, cityName.value , hotelName.value)" class="btn btn-primary btn-block form-element_btn"
[disabled]="!validEmail">Book</button>
</div>
</div>
</form>
日历component.ts
import { Component, forwardRef, Input, OnInit, ElementRef, ViewChild } from '@angular/core';
import { IgxCalendarComponent, IgxDialogComponent } from 'igniteui-angular';
import { FormControl, ControlValueAccessor, NG_VALUE_ACCESSOR, NG_VALIDATORS } from '@angular/forms';
@Component({
selector: 'app-calendar',
templateUrl: './calendar.component.html',
styleUrls: ['./calendar.component.scss'],
providers: [
{ provide: NG_VALUE_ACCESSOR, useExisting: forwardRef(() => CalendarComponent), multi: true }
]
})
export class CalendarComponent implements ControlValueAccessor, OnInit {
@ViewChild('calendar') public calendar: IgxCalendarComponent;
@ViewChild('alert') public dialog: IgxDialogComponent;
// tslint:disable-next-line:no-input-rename
@Input('date') _date;
@ViewChild('date') private elDate: ElementRef;
instance;
propagateChange: any = () => { };
ngOnInit() {
this.instance = this.calendar(this.elDate.nativeElement, {
defaultDate: this.date,
onChange: (selectedDates, dateStr, instance) => {
this.date = selectedDates[0];
}
});
}
get date() {
return this._date;
}
set date(val) {
this._date = val;
this.propagateChange(val);
}
writeValue(value) {
if (value) {
this.date = value;
this.instance.setDate(this.date, true);
}
}
registerOnChange(fn) {
this.propagateChange = fn;
}
registerOnTouched() { }
public verifyRange(dates: Date[]) {
if (dates.length > 5) {
this.calendar.selectDate(dates[0]);
this.dialog.open();
}
}
}
编译时在控制台上出现以下错误,问题首先在此行中:
ngOnInit() {
this.instance = this.calendar(this.elDate.nativeElement, {
defaultDate: this.date,
onChange: (selectedDates, dateStr, instance) => {
this.date = selectedDates[0];
}
});
}
作为参考,我在以下链接中使用了此方法:next.plnkr.co/edit/okIjPb6aUcrzx3t7edae?p=info&preview 他们使用flatpickr,而我使用igx-calendar,来自:
错误:无法调用类型缺少调用签名的表达式。 类型“ IgxCalendarComponent”没有兼容的呼叫签名。
我只希望用户选择一个日期并填写表格,例如电子邮件,城市,酒店并能够提交表格。
我的代码有什么问题?请帮助,我正在学习所有这些东西。