PrimeNg ConfirmationService - Error NG6002

957 views Asked by At

I'm building my Application Form and need a confirmation pop-up to use. but I'm getting a build error -

error Ng6002 - Appears in the NgModule.imports of appModule, but could not be resolved to an NgModule class. export declare class ConfirmationService {

my code is the following:

  • app.module.ts

    .......
    import {ConfirmationDialogModule} from 'primeng/confirmationdialog';
    import {ConfirmationService} from 'primeng/api';
    .......
    
    @NgModule({
        declaration: [....],
        imports: [
            ....,
            ConfirmationDialogModule,
            ConfirmationService,
            .....
        ]
    })
    

then I'm simply using it in my component

```
import {ConfirmationDialogModule} from 'primeng/confirmationdialog';
import {ConfirmationService} from 'primeng/api';

@Component({
   selector: 'app-form,
   templateUrl: './form.component.ts',
   styleUrls: ['./form.component.scss']
});

export class FormComponent implements onInit {
   .....
   .....
   constructor(private confirmationService: ConfirmationService){ }
   ...
   ...
   ...

   submitForm() {
      this.confirmationService.confirm({
         message: "Test Confirm",
         accept: () => { this.router.navigate['./somewhere'] }
   })
  }
}
```

I have importHelper: true & enableIvy: false I deleted the Node_Modules and installed, but nothing seems to be working!!

Any Ideas?

1

There are 1 answers

0
Manuel Auch On

Confirmation Service is a service. If you want to use it, you should declare it NOT in "imports:[]". You have to declare it in the "providers:[]"

So your code should look like this: app.module.ts

import {ConfirmationDialogModule} from 'primeng/confirmationdialog';
import {ConfirmationService} from 'primeng/api';
.....
    
@NgModule({
    declaration: [.....],
    imports: [
        ConfirmationDialogModule,
        .....
    ],
    providers: [
        ConfirmationService,
        .....
    ]
})