【发布时间】:2018-09-12 22:48:19
【问题描述】:
我收到了错误
core.es5.js:1020 ERROR 错误:未捕获(承诺中):TypeError:date.getMonth 不是函数
TypeError: date.getMonth 不是函数
当我从后端接收我的 JSON 对象时尝试使用 2 路数据绑定时,我会收到此错误。我的后端数据类型是日期,但它不会在 p 日历输入中显示备份。请帮忙!
{ "applicationId": 1, "entryDate": 1524665731000, "ongoingDescription": "<p>Ongoing entry should end in (5081421)</p>", "activeFlag": "Y" }
HTML
<div class="form-group">
<label>Date of the Ongoing Incident</label>
<br>
<p-calendar required [(ngModel)]="entry.entryDate" name="entryDate" #entryDate="ngModel" [showIcon]="true" [showTime]="true" dateFormat="mm/dd/y 'EST'" hourFormat="24"></p-calendar>
<div class="alert alert-danger" *ngIf="entryDate.touched && !entryDate.valid" >The date and time of the incident are required</div>
</div>
TS
entryDate: Date;
entry = {
}
constructor(private service: OngoingService, private route: ActivatedRoute,
private router: Router, private location: Location) {
this.id = this.route.snapshot.paramMap.get('id');
if (this.id) this.service.get(this.id).take(1).subscribe(service =>
this.entry = service);
}
ngOnInit() {
}
ngAfterContentInit() {
}
ngAfterViewInit() {
}
任何信息都会有所帮助
我也尝试分配 entryDate = new Date();和 entryDate = new Date(this.entryDate);
【问题讨论】:
-
在哪里将属性 entryDate 添加到您的条目对象?
标签: angular typescript primeng