Currently, I am developing a component using Angular 5 and Ionic 4.
My objective is to include a Refresher event to hide the refresh spinner whenever the user triggers the final function to conceal the spinner.
Provided below is an excerpt of my code:
export class UserInfoService {
constructor(private employeeService: EmployeeService) {
this.handleSuccess = this.handleSuccess.bind(this);
this.processData = this.processData.bind(this);
this.handleFinally = this.handleFinally.bind(this);
}
getEmployeeInfo(event?: Refresher) {
// console.log(event);
return this.employeeService
.getEmployeeInfo()
.map(this.handleSuccess)
.finally(this.handleFinally);
// .finally(() => {
// if (event != null) {
// console.log(' event ', event);
// event.complete();
// }
// });
}
handleFinally() {
console.log(' handle finally ', event);
if (event != null) {
console.log(' event ', event);
event.complete();
}
}
The commented portion of the code works properly, although it would be more efficient not to utilize an anonymous function. By binding it to the constructor, it can detect other events seamlessly.