我正在用Angular 5编写一个应用程序。代码运行良好,直到遇到finally块为止。在finally块中,旋转器服务未定义,但在top函数中,它已定义。
import { Injectable } from '@angular/core';
import { LicenseDataService } from './licenseData.service';
import 'rxjs/add/operator/map';
import 'rxjs/add/operator/finally';
import { Spinner } from '../../app/core/services/spinner.service';
@Injectable()
export class LicenseService {
constructor(private licenseDataService: LicenseDataService, private spinner: Spinner) { }
getWebwiseVersion() {
console.log(' get ', this.spinner); //defined
this.spinner.show();
return this.licenseDataService.getLicenseInfo()
.map(this.handleSuccess)
.finally(this.handleFinally);
}
handleFinally() {
console.log(' finally ', this.spinner); //undefined
this.spinner.hide();
}
handleSuccess(response) {
console.log(response['versionNumberField']);
return response['versionNumberField'];
}
}