角度5-为什么在一个地方未定义注入服务,而在另一个地方却未定义?

时间:2018-08-07 11:38:10

标签: angular service dependency-injection

我正在用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'];
    }

}

0 个答案:

没有答案