导出'RestService'(作为"RestService"导入)在更新vom Angular 7到12后'./rest.service.interface'(模块没有导出)中找不到



大家好,我有一个问题,几个小时都无法解决。我有一个接口:

import { HttpClient } from '@angular/common/http';
import { Response } from '@angular/http';
import { L10nTranslationService } from 'angular-l10n';
import { Observable } from 'rxjs';
import { APIConfigService } from '../../api.config.service';
import { AuthService } from '../../shared/auth.service';
import { LoggerService } from '../../shared/logger.service';
import { Kernantwort } from '../../shared/response/kernantwort.model';
import { OaseListe } from './oaseliste.model';
export declare class RestService {
isRequestRunning: boolean;
fehler: Kernantwort;
apiUrlPrefix: string;
apiUrlListId: string;
API_LIST: string;
API_CREATE: string;
API_UPDATE: string;
API_DELETE: string;
constructor(authService: AuthService, http: HttpClient, translation: L10nTranslationService, apiConfigService: APIConfigService, _logger: LoggerService);
init(): any;
liste(page: number, size: number, sort: string, sortdirection: string, search: string): Observable<OaseListe<any>>;
speichernAendern(element: any): Observable<any>;
loeschen(id: number): Observable<any>;
handleError(error: Response | any, prefix: string): Kernantwort;
getApiBaseUrl(): string;
getApiUrl(): string;
}

以及这个接口的实现:

import { Injectable } from '@angular/core';
import { Response, ResponseType } from '@angular/http';
import { L10nTranslationService } from 'angular-l10n';
import { HttpClient } from '@angular/common/http';
import { catchError, map, Observable, share, throwError as observableThrowError } from 'rxjs';
import { APIConfigService } from '../../api.config.service';
import { AuthService } from '../../shared/auth.service';
import { LoggerService } from '../../shared/logger.service';
import { Httpstatus } from '../../shared/response/httpstatus.model';
import { Kernantwort } from '../../shared/response/kernantwort.model';
import { OaseListe } from './oaseliste.model';
import { RestService } from './rest.service.interface';
const PATH_FILE = 'app/protected/immerdrin/rest.service.impl.ts';
@Injectable()
export class RestServiceImpl extends RestService {
isRequestRunning = false;
fehler: Kernantwort = null;
apiUrlPrefix: string = null;
apiUrlListId: string = null;
API_LIST = 'liste';
API_CREATE = 'hinzufuegen';
API_UPDATE = 'bearbeiten';
API_DELETE = 'loeschen';
constructor(
public authService: AuthService,
public http: HttpClient,
public translation: L10nTranslationService,
public apiConfigService: APIConfigService,
public _logger: LoggerService
) {
super(authService, http, translation,apiConfigService, _logger);
this.init();
}

当我尝试启动应用程序时,我得到以下错误:

/src/app/protect/immerdrin/rest.service.impl.ts:19:32-43-错误:在中找不到导出"RestService"(导入为"RestService("/rest.service.interface'(模块没有导出(

我不知道为什么会收到这个错误消息?因为在Angular 7中,完全相同的代码工作得很好,但现在更新到Angular 12后,出现了这个错误。有人能帮我吗?

提前感谢OASE

可能是因为你有吗

export class RestServiceImpl extends RestService

相反:

export class RestServiceImpl implement RestService

或者当你申报时:

export declare class RestService {

声明一个接口:

export declare interface RestService {

甚至,之后,您可以同时尝试这两种解决方案。

为了解决这个问题,我不得不像这样更改RestService的定义。有了这个定义,代码在Angular 12:中编译得很好

import { Response } from '@angular/http';
import { Observable } from 'rxjs';
import { Kernantwort } from '../../shared/response/kernantwort.model';
import { OaseListe } from './oaseliste.model';
//
export abstract class RestService {
isRequestRunning: boolean;
fehler: Kernantwort;
apiUrlPrefix: string;
apiUrlListId: string;
API_LIST: string;
API_CREATE: string;
API_UPDATE: string;
API_DELETE: string;
abstract init(): any;
abstract liste(page: number, size: number, sort: string, sortdirection: string, search: string): Observable<OaseListe<any>>;
abstract speichernAendern(element: any): Observable<any>;
abstract loeschen(id: number): Observable<any>;
abstract handleError(error: Response | any, prefix: string): Kernantwort;
abstract getApiBaseUrl(): string;
abstract getApiUrl(): string;
}

正如你所看到的,我将Class更改为抽象类,因此我不得不删除抽象类中不可用的构造函数Method。

最新更新