angular6 - Angular Elements:一个功能模块项目结构中的几个自定义 Web 组件可能吗?
问题描述
我想用 angular6 和 angular-elements 创建几个自定义 Web 组件。现在,如果所有内容都直接在 app.module.ts 中定义,我就可以正常工作了。
但是我的项目由几个功能模块组成,里面有自己的自定义依赖项、组件等。
我尝试使用两个引导模块扩展 main.ts,但这不起作用。
platformBrowserDynamic([{provide:LOCALE_ID,useValue:'de'}]).
bootstrapModule(AppModule, {
providers: [{provide: LOCALE_ID, useValue: 'de'}]
})
.catch(err => console.log(err));
platformBrowserDynamic([{provide: LOCALE_ID, useValue: 'de'}]).
bootstrapModule(FeatureModule, {
providers: [{provide: LOCALE_ID, useValue: 'de'}]
})
.catch(err => console.log(err));
我怎样才能做到这一点,或者我必须将我所有的功能模块放入几个“自己的”项目中?
解决方案
Typically there will only be one bootstrap module which is the root of your application.
Other features/component modules can be imported as and when they are needed. For example,
@NgModule({
imports: [
FeatureModules
],
declarations: [ErrorComponent],
providers: [
Services
],
bootstrap: [MainComponent]
})
export class AppModule {}
If your application has several roots then you can include them in the array defined by bootstrap.
See Angular's docs.
"The application launches by bootstrapping the root AppModule, which is also referred to as an entryComponent. Among other things, the bootstrapping process creates the component(s) listed in the bootstrap array and inserts each one into the browser DOM.
Each bootstrapped component is the base of its own tree of components. Inserting a bootstrapped component usually triggers a cascade of component creations that fill out that tree.
While you can put more than one component tree on a host web page, most applications have only one component tree and bootstrap a single root component.
This one root component is usually called AppComponent and is in the root module's bootstrap array."
推荐阅读
- ssis - SSIS:如何在类似条件下使用系统变量
- entity-framework - 有没有更好的方法在实体框架中执行这样的查询
- python - python ML算法在滑坡敏感性评估中的数据集问题
- c# - 使 LINQ 表达式不区分大小写
- python - 某些语言在 kivy 中未正确处理/显示!有什么关系?
- python - Pyomo 中的稀疏索引集
- yii - 在 YII2 中捕获验证失败的 Google Analytics 事件
- css - 中心 svg 表示行文本
- mongodb - $lookup 管道中的 $match 始终返回所有文档,而不是过滤
- javascript - 如何为我的进度条创建价值指示器