angularnebular

NullInjectorError: No provider for NbDialogRef! in Nebular Dialog Service


I am using NbDialogService, and I am opening a component through NbDialogService, on that dialog component I have initialized Nbdialogref private dialogref: NbDialogRef<AddContactComponent>. Now I want to also open that component without dialog box, so when I open that I get these error NullInjectorError: No provider for NbDialogRef!. Any idea how to open a compoent in dialog box and same component with navigation or routing


Solution

  • Try using @Optional() in constructor to say the service is not required.

    constructor(@Optional() private dialogRef: NbDialogRef<any>) {} 
        
    

    Note:-
    I used this when I used the same component in two places

    1. normal component page
    2. as a Model page