I have the following .ts
file
@Component({
selector: 'app-product-category',
templateUrl: './product-category.component.html',
styleUrls: ['./product-category.component.css']
})
export class ProductCategoryComponent implements OnInit {
constructor(public httpClient: HttpClient) {
}
ngOnInit() {
}
delete(name, id) {
Swal.fire({
title: 'Are you sure?',
text: 'Do you want to delete Product Category - ' + name + '?',
type: 'warning',
showCancelButton: true,
showLoaderOnConfirm: true,
confirmButtonColor: '#3085d6',
cancelButtonColor: '#d33',
confirmButtonText: 'Yes, delete it!',
preConfirm(inputValue: any): Promise<any | void> | any | void {
// I want to use httpClient to make a http request to the server here
this.httpClient.delete()...;
}
}).then((result) => {
if (result.value) {
Swal.fire(
'Deleted!',
'Your file has been deleted.',
'success'
);
}
});
}
}
I want to use the httpClient
defined in the constructor to make a network call inside the preConfirm
code block but I can't reference the variable (httpClient). How do I do it?
You can use arrow function:
preConfirm: (inputValue: any) => {
this.httpClient.delete(...)
}