加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

Angular2组件在多个模块中声明

发布时间:2020-12-17 17:42:04 所属栏目:安全 来源:网络整理
导读:我的Angular2 RC6应用程序有两个模块,我不知道如何声明共享组件. 我有一个名为spinnerComponent的组件,它在整个应用程序中使用.我在app.modules.as中定义了它: @NgModule({ imports: [BrowserModule,routing,RepairReturnModule],providers: [ ],declaratio
我的Angular2 RC6应用程序有两个模块,我不知道如何声明共享组件.

我有一个名为spinnerComponent的组件,它在整个应用程序中使用.我在app.modules.as中定义了它:

@NgModule({
    imports: [BrowserModule,routing,RepairReturnModule],providers: [ ],declarations: [AppComponent,SpinnerComponent],bootstrap: [AppComponent]
})

然后在RepairreturnModule中我再次定义它:

@NgModule({
    imports: [CommonModule],declarations: [
        SpinnerComponent
    ],providers: []
})

正如所料,我得到:

Type SpinnerComponent is part of the declarations of 2 modules:
RepairReturnModule and AppModule

我从RepairreturnModule中的声明中删除了SpinnerComponent,然后我得到:

Unhandled Promise rejection: Template parse errors: Can’t bind to
‘isRunning’ since it isn’t a known property of ‘spinner-component’.
1. If ‘spinner-component’ is an Angular component and it has ‘isRunning’ input,then verify that it is part of this module.
2. If ‘spinner-component’ is a Web Component then add “CUSTOM_ELEMENTS_SCHEMA” to the ‘@NgModule.schema’ of this component
to suppress this message. … which indicated that it is not declared.

我错过了什么?

解决方法

看到完整的代码将是有益的,但无论如何……

您可以尝试将微调器移回修复模块,然后从应用程序模块中将其导入.我使用单独的(在你的情况下它将是第三个)’共享’模块,其中共同的功能坐在这里,所以每个其他模块可以从那里导入它.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读