数据绑定不能跨角度的不同模块进行吗?



我一直在努力改进我的应用程序 - 而不是一个在应用程序模块中声明所有内容的整体应用程序 - 我想将某些组件移动到功能模块中。但是,在我从一个组件到模块外部的另一个组件有一些数据绑定的地方,这破坏了代码。

结果详细信息组件模板

<div class="col-9">
<app-links-table [loaded]="dataLoaded" [dataLinkResult]="dataLinkResult"></app-links-table>
</div>

ResultDetailsComponent现在属于ItemsModule,我在其中声明和导出它。

@NgModule({
declarations: [
ResultDetailsComponent,
],
exports: [
ResultDetailsComponent
]
})
export class ItemsModule { }

LinksTableComponent(app-links-table(包含数据绑定的正确输入

export class LinksTableComponent {
@Input() loaded: boolean;
@Input() dataLinkResult: Link[];
}

目前,这仍然在主AppModule中声明,尽管我计划将其移至它自己的功能模块中。

@NgModule({
declarations: [
LinksTableComponent,
],
exports: [
LinksTableComponent
],
bootstrap: [AppComponent]
})
export class AppModule { }

答案是我现在需要创建一个服务来在这些组件之间进行通信吗?还是我的结构从根本上是错误的?

将组件重构为单个模块总是好的。

模块以角度形式形成编译上下文。但是在这样做时,您需要注意一些事情......

有些功能模块不会在其他模块中导入
  1. (至少不会在许多模块中导入(。
  2. 您将在所有或大部分功能模块中导入共享模块。

因此,请根据上述几点查看如何使用链接表组件并重构代码。

关于错误...

因此,如果要在模块"A"的组件中使用模块"B"的组件,模块">

A"必须导入模块"B"(现在不要在其他模块中导入应用程序模块:P。重构以将组件移动到另一个模块中(。

万事如意。

最新更新