Hi guys I've a problem I cannot fix for several hours now. I have an 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;
}
And the implementation of this interface:
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();
}
When I try to start the application I get the following error:
./src/app/protected/immerdrin/rest.service.impl.ts:19:32-43 - Error: export 'RestService' (imported as 'RestService') was not found in './rest.service.interface' (module has no exports)
And I have no clue why I get this error message? Because in Angular 7 the exact same code worked well, but now after update to Angular 12 this error occurs. Is anybody able to help me?
Thanks in advance OASE
CodePudding user response:
Could it be because you have
export class RestServiceImpl extends RestService
instead:
export class RestServiceImpl implement RestService
Even, afterwards, you could try both solutions at the same time.
Or maybe when you declare this:
export declare class RestService {
declare an interface instead:
export declare interface RestService {
CodePudding user response:
To solve this issue I had to change de definition of the RestService like this. With this definition the code compiles fine in 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;
}
As you can see I changed the Class to an abstract class and therefore I had to remove the constructor Method which is not available in an abstract class.