Issue
I am trying to test a function by passing in a date as a parameter to a function but I'm not to sure where I'm going wrong. It gives an error of "Argument of type 'number' is not assignable to parameter of type 'Date'." when the code is structured this way:
import { Component, OnInit } from '@angular/core';
import { DamageAssessmentReportService } from 'src/app/damage-assessment-report.service';
@Component({
selector: 'app-fa-daform',
templateUrl: './fa-daform.component.html',
styleUrls: ['./fa-daform.component.css']
})
export class FADAFormComponent implements OnInit {
constructor(private damageAssessmentReportService : DamageAssessmentReportService) { }
//assessmentDescription: string, author: string, reportDateTime: Date
createNewDAReport(){
this.damageAssessmentReportService.createDAReport('Testing1','Testing2', 2022-10-10).subscribe(()=>{
})
}
ngOnInit(): void {
}
}
But changes to "Argument of type 'string' is not assignable to parameter of type 'Date'.ts(2345)" when the code is changed to :
import { Component, OnInit } from '@angular/core';
import { DamageAssessmentReportService } from 'src/app/damage-assessment-report.service';
@Component({
selector: 'app-fa-daform',
templateUrl: './fa-daform.component.html',
styleUrls: ['./fa-daform.component.css']
})
export class FADAFormComponent implements OnInit {
constructor(private damageAssessmentReportService : DamageAssessmentReportService) { }
//assessmentDescription: string, author: string, reportDateTime: Date
createNewDAReport(){
this.damageAssessmentReportService.createDAReport('Testing1','Testing2', '2022-10-10').subscribe(()=>{
})
}
ngOnInit(): void {
}
}
Solution
createDAReport
is expecting a Date object.
this.damageAssessmentReportService.createDAReport('Testing1','Testing2', new Date(2020, 9, 10)).subscribe(() => {
...
});
Answered By - Tom
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.