After upgrading angular 2 to RC5, i was getting warnings like below asking me to move my components to module declarations:
NgModule AppModule uses AcademylistComponent via "entryComponents" but it was neither declared nor imported! This warning will become an error after final.
I was refering to these components in my router config file. What looked like this:
import {provideRouter,RouterConfig} from '@angular/router';
import {AcademylistComponent} from '../modules/home/component/academyList.component';
import {CourselistComponent} from '../modules/home/component/courseList.component';
import {CreateacademyComponent} from '../modules/home/component/createAcademy.component';
import {ReportsComponent} from '../modules/home/component/reports.component';
import {AuthenticatedGuard} from '../guards/authenticated.guard';
export const routes: RouterConfig = [
{
path: '',
redirectTo:'/home',
terminal:true},
{
path: 'home',
canActivate: [AuthenticatedGuard],
children: [
{path: '', component: AcademylistComponent},
{path: 'my-academies', component: AcademylistComponent},
{path: 'my-courses', component: CourselistComponent},
{path: 'create-academy', component: CreateacademyComponent},
{path: 'reports', component: ReportsComponent}
]
}
];
export const APP_ROUTER_PROVIDERS = [
provideRouter(routes)
];
When i moved the components to ng module's declarations
array and imported them there, the routes config file did started giving me Cannot find name
errors.
So how do i use module declarations in this case?
NgModules configure the injector and the compiler and help organize related things together. An NgModule is a class marked by the @NgModule decorator. @NgModule takes a metadata object that describes how to compile a component's template and how to create an injector at runtime.
Angular Concepts declarations are to make directives (including components and pipes) from the current module available to other directives in the current module. Selectors of directives, components or pipes are only matched against the HTML if they are declared or imported.
There are two types of modules, root modules and feature modules.
Even if you declare them in your routes, You still have to declare the components used in the routes in the NgModule.
@NgModule({
declarations: [
AcademylistComponent,
//.. and so on
],
providers: [
APP_ROUTER_PROVIDERS
]
})
export class AppModule {}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With