I am using a daterange plugin called Lightpick and if the user picks a start date and end date. thats when I'll be calling a method on my service.ts
here is my code:
Service.ts
const httpOptions = {
headers: new HttpHeaders({ 'Content-Type': 'application/json; charset=utf-8' })
}
public getAttedanceRecord(data): Observable<any> {
return this.http.post(url, data, httpOptions);
}
component.ts
import { JsonFileService } from '../json-file.service';
import * as moment from 'moment-timezone';
import 'moment-duration-format';
import Lightpick from 'lightpick';
export class TimeRecordsComponent implements OnInit {
constructor(public JsonFileService: JsonFileService) {}
ngOnInit() {
var picker = new Lightpick({
field: document.getElementById('datepicker'),
singleDate: false,
footer: true,
selectForward: true,
onSelect: function(start, end){
let startDate = start.format();
let endDate = end.format();
console.log(startDate + " " + endDate);
this.JsonFileService.getAttedanceRecord({
EmployeeId: "00000000-0000-0000-0000-000000000001",
DateFrom: startDate,
DateTo: endDate,
TimeZone: "China Standard Time",
CountryCode: "PHL",
TenantId: "00000000-0000-0000-0000-000000000001",
CompanyId: "00000000-0000-0000-0000-000000000001"
}).subscribe(data => {
console.log(data);
});
}
});
}
}
When I set a start and end date it always throws this error.
I am aware that i need to call the method with a different approach so that i can use it. But I don't know how.
Please help me on my development.

ViewChildinstead.