I set date_work
to Date data type. But when I check the data type using the command console.log(typeof master.date_work)
it appears for some reason the type of string
. And because of this, when I use the getTime()
function such an error occurs. How can I change the string data type to Date?
TypeError: master.date_work.getTime is not a function
Model:
export interface Masters {
master_id?: string,
full_name: string,
comment: string,
date_work: Date,
teams_id: string
}
ts:
reports: Rep4Hours[]
masters: Masters[]
teams: Teams[]
filteredTeams = []
filteredMasters = []
onSelectedReport(reportId) {
this.selectedReport = this.reports.find(
el => {
return el.report_id === reportId
}
)
if (this.teamsService) {
this.teamsService.fetch().subscribe(
team => {
this.teams = team
this.filteredTeams = this.teams.filter(
(team) => team.team_id == this.selectedReport.teams_id
)
if (this.mastersService) {
this.mastersService.fetch().subscribe(
master => {
this.filteredMasters = []
this.masters = master
for(let team of this.filteredTeams){
for(let master of this.masters){
if(master.teams_id == team.team_id){
if (Math.max(...this.masters.map(master => master.date_work.getTime()))) {
if (master.date_work <= this.selectedReport.report_date) {
this.filteredMasters.push(master)
}
}
}
}
}
}
)
}
}
)
}
}