I have this file and its code is like
import { Injectable } from '@angular/core';
import { I18n } from '@ngx-translate/i18n-polyfill';
import { isNumber } from 'lodash';
import { ConfirmationService, MessageService } from 'primeng/api';
export enum ConfirmationType {
Delete,
Navigate,
Unsaved,
}
export enum SuccessMessage {
Cloned,
Created,
Deleted,
Saved,
Reverted,
}
@Injectable()
export class MessagingService {
constructor(
private readonly _i18n: I18n,
// tslint:disable-next-line:ban-types
private readonly _messageService: MessageService,
private readonly _confirmationService: ConfirmationService,
) { }
And the error that I get is:
Error: Cannot instantiate cyclic dependency! MessagingService
CodePudding user response:
This error occurred because of that you instantiated the MessagingService
inside of MessageService
too.
This way you created a cycle of instantiation.
MessagingService
-> MessageService
-> MessagingService
-> ...
You have to restruct your code in a way that they can access the required data and functions without need of instantiate each other.