angular - 我们在 ngModule 装饰器下声明的类中写了什么样的代码?

标签 angular typescript dependency-injection ng-modules

我刚刚开始学习 Angular。我遇到过几个在空的 class 上使用 ngModule 装饰器的例子。

我想知道的是...... class 直接在 ngModule 装饰器下面声明只是用来初始化模块还是有其他用途?

最佳答案

例如,您可以使用构造函数或实现 ngDoBootstrap在第一次加载惰性加载模块时执行代码(初始化)

您还可以向构造函数注入(inject)服务,以便在应用程序或延迟加载模块初始化时由 DI 实例化它们。

我不记得看到过其他例子。 除此之外,它只包含 @NgModule() 装饰器和那里提供的信息。 (构建应用程序时可能会生成一些额外的代码)

另请参阅 https://angular.io/guide/entry-components 中的 ngDoBootstrap 注释

关于angular - 我们在 ngModule 装饰器下声明的类中写了什么样的代码?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39911211/

相关文章:

angular - 在登录页面请求之前检查 session

css - Angular 4 CSS DIV 背景图像绑定(bind)不起作用

javascript - TypeScript 接口(interface)未定义

javascript - 为什么我无法在 Ionic 4 中创建 radio 警报?

spring - 无法在可访问已部署 JAR 的 Wildfly 中加载 Spring 框架库

php - PHP 中依赖注入(inject)容器的直接示例

ios - Typhoon 注入(inject) - 使用初始化程序注入(inject)参数时崩溃

angular - Material 按钮没有样式

angular - 升级到 angular 5 后 webpack 命令失败

angular - 如何在 Angular 库中包含图像?