0

I have implemented angular 2 routing but it's throwing error as

Uncaught (in promise): Error: No component factory found for AdminpanelComponent. Did you add it to @NgModule.entryComponents?

Even though I have entry in app.module entryComponents still I am facing this errro. Details of code below.

app.routes.ts

import {provideRouter, RouterConfig} from '@angular/router';
import { AdminpanelComponent } from './components/adminpanel/adminpanel.component';
import { LoginComponent } from './components/login/login.component';

export const AppRoutes: any = [
    { path: '', component: 'LoginComponent'},
    { path: 'login', component: LoginComponent },
    { path: 'admin', component: AdminpanelComponent },
    { path: '**', component: LoginComponent }
];

export const AppComponents: any = [
    LoginComponent,
    AdminpanelComponent
];

app.module.ts

 import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { HttpModule } from '@angular/http';
import { AuthService} from './services/auth.service'

import { AppComponent } from './app.component';
import { NavbarComponent } from './components/navbar/navbar.component';
import { AdminpanelComponent } from './components/adminpanel/adminpanel.component';
import { BalldetailsComponent } from './components/balldetails/balldetails.component';
import { LoginComponent } from './components/login/login.component';

import { RouterModule } from "@angular/router";
import { AppComponents, AppRoutes } from "./app.routes";


@NgModule({
  declarations: [
    AppComponent,
    AppComponents,
    NavbarComponent,
    AdminpanelComponent,
    BalldetailsComponent,
    LoginComponent
  ],
  imports: [
    BrowserModule,
    HttpModule,
    RouterModule,
    RouterModule.forRoot(AppRoutes)
  ],
  providers: [AuthService],
  bootstrap: [AppComponent],
  entryComponents: [
    AppComponent,
    AppComponents,
    NavbarComponent,
    AdminpanelComponent,
    BalldetailsComponent,
    LoginComponent
  ]
})
export class AppModule { }

app.component.html

<router-outlet></router-outlet>

Any help would be highly appreciated...Thanks

Akki619
  • 2,386
  • 6
  • 26
  • 56
  • I don't see it in your entryComponents – JanS Apr 27 '18 at 14:04
  • As per my understanding, we put entry in declaration which is entry point? Am I wrong here? – Akki619 Apr 27 '18 at 14:14
  • https://stackoverflow.com/questions/39756192/what-is-entrycomponents-in-angular-ngmodule – JanS Apr 27 '18 at 14:21
  • You are declaring it two times: standalone and as an element of the AppComponents-array (btw you shouldn't name variables starting with uppercase). Also you are importing RouterModule two times. And you are missing CommonModule (which you need for *ngFor and other angular directives which you are probably using) – Phil Apr 27 '18 at 14:30
  • @JanS added entryComponents as per the link but still error is there? can u guide me what is wrong? – Akki619 Apr 27 '18 at 14:44

0 Answers0