如何在Angular 6库中创建延迟加载的特征模块?

时间:2018-08-07 08:12:12

标签: angular angular-cli angular6 ng-packagr angular-library

我使用Angular CLI 6命令创建了一个库。

基本上,库是一个功能模块,它包含许多子功能模块,这些功能模块通过路由连接(延迟加载)。

我在运行时遇到以下错误

 public void UserType(String user){

        if (user.contentEquals("admin")){
            UI.add.setVisibility(View.VISIBLE);
            UI.delete.setVisibility(View.VISIBLE);
            UI.edit.setVisibility(View.VISIBLE);
            UI.commit.setVisibility(View.VISIBLE);
        }else if (user.contentEquals("user")){
            UI.add.setVisibility(View.VISIBLE);
            UI.delete.setVisibility(View.VISIBLE);
            UI.edit.setVisibility(View.GONE);
            UI.commit.setVisibility(View.GONE);
        }
    }

我尝试了所有可能的路径

ERROR Error: Uncaught (in promise): Error: Cannot find module "./contact/contact.module".

但无济于事

延迟加载是否支持ng-packagr的angular库?

3 个答案:

答案 0 :(得分:0)

您必须使用从app开始的完整文件路径

{ path: 'contact', loadChildren: 'app/...../contact/contact.module#ContactModule' }

请检查official guides

答案 1 :(得分:0)

您必须使用根文件夹中的路径,并且应将app.routing放置在app文件夹中 像src-app-> app.routing.module.ts

{ path: 'contact', loadChildren: './app/...../contact/contact.module#ContactModule' }

答案 2 :(得分:0)

写入路径,例如: {path:'contact',loadChildren:()=> contactModule}