Angular2: Lazy Loading in Angular2 Error: Cannot find ‘default’ in module

Standard

While implementing Lazy Loading in Angular 2, came across this error:

EXCEPTION: Uncaught (in promise): Error: Cannot find ‘default’ in ‘Scripts/app/search-movies/search-movies-main.module’

screenshot_5

Solution:

as stated in official documentation https://angular.io/docs/ts/latest/guide/router.html

If we look closer at the loadChildren string, we can see that it maps directly to our crisis-center.module file where we previously built out our Crisis Center feature area. After the path to the file we use a # to denote where our file path ends and to tell the Router the name of our CrisisCenter NgModule. If we look in our crisis-center.module file, we can see it matches name of our exported NgModule class.

Add the exported class name of your module to the loadChildren string after hash(#)

{
    path: '',
    loadChildren: 'app/search-movies/search-movies-main.module'
}

change to

{
    path: '',
    loadChildren: 'app/search-movies/search-movies-main.module#SearchMoviesMainModule'
}

 

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s