I encountered an error message stating "ConfirmationDialogComponent: No component factory found" while attempting to navigate through the

After successfully implementing the canDeactivate guard on the add and edit components, an issue arose when attempting to navigate from TypeScript code rather than using routerLink. The error message received was:

"Error: No component factory found for ConfirmationDialogComponent. Did you add it to @NgModule.entryComponents?".

Below are the routing settings:

const routes: Routes = [
  {
    path: 'dashboard',
    component: DashboardComponent,
    canActivate: [AuthenticationGuardService], children: []
  },
  ...
  { path: 'report-project-list', component: ReportProjectListComponent, canActivate: [AuthenticationGuardService] }
];

Snippet of the component code leading to the navigation issue:

@Component({
        selector: 'app-engagement-survey',
        templateUrl: './engagement-survey.component.html',
})
export class EngagementSurveyComponent implements OnInit {


        constructor(public dialog: MatDialog, private router: Router) {}

        ngOnInit() {

                this.subscription = this.clientService.currentClient.subscribe(currentClientValue => {

                        if (this.isClientChanged) {
                          this.router.navigate(['/home']); **// ISSUE HERE**
                        } else {
                          this.isClientChanged = true;
                        }
                });
        }

        canDeactivate(): Observable<boolean> {
                if (!this.dataSaved) {
                        const dialogRef = this.dialog.open(ConfirmationDialogComponent, {
                                width: '350px',
                                data: 'Leave Site? Changes you made may not be saved? '
                        });
                        return dialogRef.afterClosed();
                } else {
                        return of(true);
                }
        }
}

Implementation of the can deactivate guard is as follows:

import { Injectable } from '@angular/core';
import { CanDeactivate } from '@angular/router';
...

@Injectable({
    providedIn: 'root'
})
export class CanDeactivateGuard implements CanDeactivate<CanComponentDeactivate>  {
    canDeactivate(component: CanComponentDeactivate): Observable<boolean> {
      return  component.canDeactivate ?   component.canDeactivate() : of(true);
    }
}

The issue appears to occur only when using this.router.navigate() instead of routerLink directive.

Answer №1

Ensure that you include the ConfirmationDialogComponent in the entry components of your module.

@NgModule({
  declarations: [

  ],
  exports: [

  ],
  providers: [

  ],
  entryComponents: [
    ConfirmationDialogComponent

  ]
})
export class AppModule { }

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

How can I modify the body background or background-color when navigating routes in Angular 4?

Is there a way to update the body background or background-color when changing routes in Angular 4? ...

The directive subscription remains inactive even when the subject triggers the next function

Plunkr: https://plnkr.co/edit/KfPfVSbZm087uIPvFEkM?p=preview I have developed a service that serves as an API for a modal component. In addition, there is a directive available that can be used to apply a class to any element when the modal is open. Howev ...

Both undefined and null are sometimes allowed as values in conditional types, even when they should not be

Do you think this code should trigger a compiler error? type Test<T extends number | string> = { v: T extends number ? true : false } const test: Test<1> = { v: undefined } Is there something I am overlooking? Appreciate your help! ...

The functionality of Ionic Cordova is currently inaccessible

Currently utilizing the Ionic Native Calendar plugin in version 3.9.2 of Ionic framework. The module has been successfully installed and included in the app module. Below is the snippet where the calendar is being called: import { Component } from ' ...

What is the reason for importing this JS module in TypeScript with a "default" property?

This particular code snippet comes from a specialized i18n module, situated within ./esm/locale/en.js: import cardinal from '../rules/rule5'; import ordinal from '../rules/rule42'; var pluralRule = { ordinal: ordinal, cardinal: card ...

Issue with AngularJS UI Router not loading the inline template and controller

I am trying out UI Router for the first time in my AngularJS project. I am facing an issue where, when I click on a link to view a post, it doesn't display. The post template is not visible and I remain on the home page. The URL flashes as http://loc ...

What is the best approach for presenting multiple entries with identical IDs in a table using Angular?

I obtained a JSON response in the following structure; https://jsonplaceholder.typicode.com/posts My goal is to format the table to resemble the attached image structure. However, my current implementation is displaying repeating user IDs. How can I adju ...

A guide on efficient management of multiple props in React Router v6 by utilizing a wrapper component

I've attempted to: element: <ProtectedRoute component={ProjectBoard} prop1={prop1} prop2={prop2}/> The error message I receive is "Type '({ prop1, prop2 }: Props) => JSX.Element' is not assignable to type 'ComponentType<{} ...

When working with Typescript, encountering difficulty in locating or importing modules from a parent directory that is one level above the tsconfig.json file is

My project's directory structure looks like this: Main/project-root/* (tsconfig.json, packages.json, app.ts, etc are located here) Main/shared/* (shared.ts is located here along with other ts files, no packages.json or any other files) Let's ...

Is there a way for me to trigger an action based on the Observable's return

I'm eager to optimize this by implementing observables: post<T>( url: string, body: any, params?: HttpParams, headers?: HttpHeaders ): Observable<T> { this.isLoading$.next(true); const res = this.http .p ...

Angular 2's NgFor directive is designed to work with data structures that can be iterated over,

Currently, I am implementing the Reactive form pattern in my Angular 2 project. The goal is to dynamically populate a container with answers that are fetched and populated using an http call. The structure of the Reactive form object is as follows: publi ...

A beginner's guide to setting up Bootstrap on Angular 8

Struggling with installing Bootstrap in Angular 8? Followed multiple guides but still facing issues? Check out this helpful article on getting-started for a step-by-step guide. ...

Determine the type of function arguments based on provided hints in TypeScript

It's common to encounter situations like this where TypeScript struggles to infer types due to lack of context. Is there a way to explicitly declare the type of function for the compiler? router.get('/get', imget); router.get('/send&a ...

Is it beneficial to utilize an interface for constructing a class model?

The Interface: export interface IAddEditGeneralDictionary { Code: string; StartDate?: Date | string; FinishDate?: Date | string; Name: string; } The Realization: export class AddEditGeneralDictionary implements IAddEditGe ...

Disabling behavior subjects in Angular 8: A guide to unsubscribing

Hello, I am currently working on an Angular8 application where I am utilizing Replay Subject and Behavior Subject. I have noticed that when initially clicking, the API is only hit once. However, if I switch between tabs, the subscription triggers multiple ...

Displaying code within an Angular 2 template

Working on an Angular 2 project and facing a challenge in displaying C# code within the template, which may later be styled with syntax highlighter. The issue arises when attempting to insert the C# code into the Angular 2 template, resulting in template ...

What is the process of creating conditional content projection in Angular?

Looking to implement an optional content projection feature in Angular. Here's the desired structure as an example: <app-root> <app-header></app-header> </app-root> By default, a header is displayed here. <app-root&g ...

What is the process for incorporating the error type of useQueries in a TypeScript project?

Currently, I am utilizing react-query's useQueries function to create a unique custom hook named useArtists: type SuccessResponse = { artist: { name: string } }; const fetchArtist = async (artistId: string): Promise<SuccessResponse> =& ...

Angular JSON converter - Transform XML data to JSON format

Struggling to convert XML API response to JSON using xml2js library, facing issues with getting 'undefined' in the console. Here is my API service: export class WordgameService { public apiUrl = "http://www.wordgamedictionary.com/api/v1/reference ...

Issue with Angular's reactive form: Dynamic validator fails to update control validity

When designing my form, I encountered a specific requirement where one control should only be required if another control has a value. To achieve this functionality, I implemented the following structure: profileGroup = this.fb.group({ username: ['&a ...