In my service file, I have two methods called getData and delete. The data is sourced from an API and the getData method works fine.
However, I am facing a problem with the delete() method where siteId is not being read correctly. When I click the save button, it should be able to identify the siteId and delete the relevant data. I suspect that there might be an issue with how I've implemented the code in both the service file and component file.
This is what my service.ts file looks like:
datasites : Data
getData(): Promise<PagedResult<data>> {
const url = `${environment.API_URL}/data/GetData`;
return this.httpClient.get<PagedResult<data>>(url).toPromise();
}
delete(): Promise<Data>{
alert(2);
const siteId = this.datasites.principalId;
const url = `${environment.ADMIN_API_URL}/sites/DeleteSite?siteId=`+ siteId;
console.log(siteId);
return this.httpClient.post<Sites>(url, request).toPromise();
}
And here is the component.ts file:
async ngOnInit(){
alert("***********");
this.data = await this.dataService.getData();
console.log(this.data[0].principalId);
this.deleteSiteId = this.data[0].principalId;
console.log(this.deleteSiteId);
}
delete(data){
alert(aaaaaaaaa);
this.dataService.delete(data);
console.log(data.principalId);
}
showButtons: boolean = false;
clickEvent(data){
data.isClicked = !data.isClicked;
this.showButtons = !data.showButtons;
}
And finally, the .html file:
<div *ngIf="showButtons">
<button (click)="delete()">Save</button>
</div>