【发布时间】:2019-10-05 09:06:50
【问题描述】:
对于 Angular-7,我正在尝试使用 Angular 组件打字稿中的选择选项来生成出生日期,并分别生成日期、月份和年份。
client.component.ts
import { Component, OnInit, ElementRef, NgZone, ViewChild } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { ApiService } from '../../shared/services/api.service';
import { TokenService } from '../../shared/services/token.service';
import { Router } from '@angular/router';
const getMonth = (idx) => {
var objDate = new Date();
objDate.setDate(1);
objDate.setMonth(idx-1);
var locale = "en-us",
month = objDate.toLocaleString(locale, { month: "long" });
return month;
}
@Component({
selector: 'app-client-quotes-landing',
templateUrl: './client-quotes-landing.component.html',
styleUrls: ['./client-quotes-landing.component.scss']
})
export class ClientQuotesLandingComponent implements OnInit {
public title = 'Places';
public addrKeys: string[];
public addr: object;
months = Array(12).fill(0).map((i,idx) => getMonth(idx + 1));
public form = {
first_name : null,
last_name : null,
dob_day : null,
dob_month : null,
dob_year : null,
};
public error = {
'first_name' : null,
'last_name' : null,
'dob_day' : null,
'dob_month' : null,
'dob_year' : null,
};
public get days() {
const dayCount = this.getDaysInMonth(this.form.dob_year, this.form.dob_month);
return Array(dayCount).fill(0).map((i,idx) => idx +1)
}
public getDaysInMonth(year: number, month: number) {
return 32 - new Date(year, month - 1, 32).getDate();
}
constructor(
private api: ApiService,
private token: TokenService,
private router: Router,
private notify: SnotifyService,
private zone: NgZone,
) {
}
ngOnInit() {
}
}
我想从以下位置访问 dob_month 和 dob_year:
公开表格 = {...}
然后,我得到了这个错误:
src/app/pages/client-quotes-landing/client-quotes-landing.component.ts(94,47) 中的错误:错误 TS2339:“ClientQuotesLandingComponent”类型上不存在属性“dob_year”。 src/app/pages/client-quotes-landing/client-quotes-landing.component.ts(94,62):错误 TS2339:“ClientQuotesLandingComponent”类型上不存在属性“dob_month”。
错误来自:
public get days() {
const dayCount = this.getDaysInMonth(this.form.dob_year, this.form.dob_month);
return Array(dayCount).fill(0).map((i,idx) => idx +1)
}
如何解决此错误?
【问题讨论】:
标签: angular