在app.module.ts中导入外部模块

马文·埃里克森(Marvin Ericson)

我想知道Angular 4中的模块,如果我有这个模块:

@NgModule({
  imports: [
    ...
    ...
  ],
  declarations: [
    OneComponent
  ],
})
export class OneModule { }

在我的app.modules.ts中,我在导入中使用了这个模块

@NgModule({
  imports: [
    ...
    OneModule
    ...
  ],
})
export class AppModule { }

这是否意味着OneComponent在应用模块中声明了?

我遇到了TimeAgoModule包的问题,​​如果我将其放在OneModule导入中,则OneComponent应该看到时间,但是它说没有定义时间,并且如果我将OneComponent从OneModule声明移动到AppModule声明,则一切都是正确的精细。到底是什么主意?

沙申克·维维克

您需要使用exportOneComponent。

@NgModule({
  imports: [
    ...
    ...
  ],
  exports: [OneComponent],
  declarations: [
    OneComponent
  ],
})
export class OneModule { }

通过导出一个component,您可以告诉Angle模块该特定模块component可以在模块外部使用,并且可以在其他模块中重复使用。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

如何使用importlib.import_module在Python中导入模块

如何在Node中导入全局模块?我收到“错误:找不到模块<module>”?

在app.component.ts中导入HTTP_PROVIDERS

找不到模块“ ./app.module.ngfactory”

从app.module.ts文件中的“角度”将*导入为角度

在Coq Module系统中导入<Module>与Include <Module>

即使在app.module中导入了不使用的模块并且不使用它,angular-cli也会删除未使用的模块吗?

在Powershell中导入模块,例如将<import <module> as as <alias>导入

如何使用ModuleWithProviders在Angular Module中导入其他模块

app.module.browser.ts和app.module.shared.ts有什么区别

为什么要在app.module.ts中导入{HttpClientModule}

无法将FileOpener导入我的app.module.ts

根据官方文档在app.module中导入@ angular / fire时输入错误?

在App Module中导入可注入值到SubModule时

无法在app.module中导入MatDialogModule

在没有app.module.ts文件的情况下在多个模块之间共享组件

错误[ERR_MODULE_NOT_FOUND]:找不到从build \ server.js导入的模块“ build \ app”

无法从模块“ RootModule”实例化文件“ app.module.ts”

在 Jython StreamSets 中导入 python 模块 - ImportError: No module named

在类中导入模块时出现“NameError: name [module] is not defined”

未找到 ./src/app/app.module.ts 模块中的错误

在 App 和每个 Module angular 2 中导入 sharedModule

生成模块会在 app.module.ts 中的路径中添加一个额外的斜线

无法导入模块“app”:使用 Claudiajs 在 AWS 中的 Function.Module._resolveFilename 处出错

Angular:模块 src/app/app.module.ts 的元数据版本不匹配,发现版本 3,预期版本 4

Angular 2+,有什么方法可以声明一个模块中的所有组件,然后在 app.module.ts 中导入?

在flask app中导入模块的问题

我应该如何在 app.module.ts 中导入 MatDrawer 和 MatDrawerContainer?角 9

无法在 Xcode 中导入模块 app_setings - Flutter