首页 > 解决方案 > Angular 5 延迟加载不起作用。共享模块不工作

问题描述

我们正在尝试在我们的项目中实现延迟加载。但我有一个奇怪的错误。基本上,我为组件创建了一个模块,并在 app.module 中使用了 loadchildren。但是像这样在 Html 中的那个组件中使用了另一个组件

<cr-configure-button></cr-configure-button>

所以对于这个组件,我收到了这个错误

Can't bind to 'hub' since it isn't a known property of 'cr-configure-button'.
1. If 'cr-configure-button' is an Angular component and it has 'hub' input, then verify that it is part of this module.
2. If 'cr-configure-button' is a Web Component then add 'CUSTOM_ELEMENTS_SCHEMA' to the '@NgModule.schemas' of this component to suppress this message.
3. To allow any property add 'NO_ERRORS_SCHEMA' to the '@NgModule.schemas' of this component

对于这个组件,我创建了一个共享模块来导出这个组件。请看下面的代码

请帮忙。

先感谢您

app.module.ts

 { path: 'modules', loadChildren: './hubs/hubs.module#HubsModule' },

hubs.module.ts

import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';

import { HubsRoutingModule } from './hubs-routing.module';
import { HubsComponent } from './hubs.component';
import { SharedModule } from '@shared/shared.module';

@NgModule({
  imports: [
    CommonModule,
    HubsRoutingModule,
    SharedModule,
  ],

  declarations: [
    HubsComponent,
  ],

})
export class HubsModule { }

共享模块.ts

import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { CrConfigureButtonComponent } from './components/buttons/cr-configure-button';

@NgModule({
  imports: [
    CommonModule,
  ],
  declarations: [CrConfigureButtonComponent],
  exports: [CrConfigureButtonComponent],
})
export class SharedModule { }

标签: javascriptangulartypescriptangular5

解决方案


推荐阅读