Angular CLI ERROR in Cannot read property 'loadChildren' of null

前端 未结 11 2214
青春惊慌失措
青春惊慌失措 2021-01-01 12:24

I\'m converting a project to use angular cli and everything is working (once it\'s build) but i\'ve got a weird behaviour during build.

with ng serve I

11条回答
  •  一整个雨季
    2021-01-01 12:48

    I also ran into a similar issue with the Angular CLI v1.6.

    In my case I was not using .concat() or any other kind of dynamic manipulation of the router definitions.

    Rather I had a function in a data property of a route which was an anonymous arrow function. Changing this to a named exported function solved the issue for me.

    Before:

     {
        path: ':id',
        component: ProductDetailComponent,
        data: {
            breadcrumb: (data: any, params: any) => {
                let id = params['id'];
                return id === 'create' ? 'New Product' : data.product.ShortDescription;
            }
        }
    }
    

    After:

    {
        path: ':id',
        component: ProductDetailComponent,
        data: { breadcrumb: getBreadcrumb }
    }
    
    export function getBreadcrumb(data: any, params: any): string {
        let id = params['id'];
        return id === 'create' ? 'New Product' : data.product.ShortDescription;
    }
    

提交回复
热议问题