【问题标题】:InjectionToken mat-select-scroll-strategy error with angular material lazy loading problem带有角度材料延迟加载问题的 InjectionToken mat-select-scroll-strategy 错误
【发布时间】:2020-10-14 17:15:24
【问题描述】:

我的 Angular 9 应用程序中有两个模块 只有一个模块使用角材料。 所以我的 app.module.ts 不加载它,我使用延迟加载 但是当我运行该应用程序时,它会显示错误

NullInjectorError: R3InjectorError(t)[InjectionToken mat-select-scroll-strategy -> InjectionToken mat-select-scroll-strategy -> InjectionToken mat-select-scroll-strategy -> InjectionToken mat-select-scroll-strategy]: NullInjectorError: InjectionToken mat-select-scroll-strategy 没有提供者!

请有人帮忙。

【问题讨论】:

标签: angular angular-material lazy-loading


【解决方案1】:

我遇到了同样的情况。解决我的方法是在app.module.ts 中导入MatAutocompleteModule,即使您在子模块中需要它。

app.module.ts

import {MatAutocompleteModule} from '@angular/material/autocomplete';


imports: [
  MatAutocompleteModule,
]

【讨论】:

  • 感谢您的回答,它也为我解决了这个问题。我想知道你是否知道为什么 app.module.ts 中也需要它?
【解决方案2】:

为我消除错误的是在AppModule 中包含MatDialogModuleMatMenuModule,这不是延迟加载的:

import { MatDialogModule } from '@angular/material/dialog';
import { MatMenuModule } from '@angular/material/menu';

然后mat-menu终于又工作了!

为什么会这样?

我的猜测是一些@angular/material 组件对这两个特定模块有一些隐式依赖。希望他们在未来修复它,所以你不需要这个......

【讨论】:

  • 为什么解决了这个问题?
  • @pixparker 更新答案^
【解决方案3】:

就我而言,出现了路由错误。在使用延迟加载的父路径中,我放置了书签组件。早上我还提到了带有标签的相同组件。

家长:

{
    path: MyProfileRoutesEnum.settings,
    data: {[MY_DATA_PARAM]: true},
    component: MySettingsContainerComponent, // need to delete this
    loadChildren: () => import('./my-settings/my-settings.module').then((m) => m.MySettingsModule),
},

孩子:

{
    path: `:${TAB_PARAM}`,
    component: MySettingsContainerComponent,
},

必须是父母:

{
    path: MyProfileRoutesEnum.settings,
    data: {[MY_DATA_PARAM]: true},
    loadChildren: () => import('./my-settings/my-settings.module').then((m) => m.MySettingsModule),
},

【讨论】:

    猜你喜欢
    • 2020-06-12
    • 2018-03-24
    • 2019-08-22
    • 2021-12-18
    • 1970-01-01
    • 2018-08-16
    • 2023-04-11
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多