&引用;试图查找引导程序代码,但未能;当在Angular 5中引导多个组件时,它能正常工作吗?
所以我遇到了一个非常非常奇怪的问题。我正在尝试在Angular 5项目中引导多个组件,因此我可以简单地执行以下操作:&引用;试图查找引导程序代码,但未能;当在Angular 5中引导多个组件时,它能正常工作吗?,angular,angular5,angular-bootstrap,Angular,Angular5,Angular Bootstrap,所以我遇到了一个非常非常奇怪的问题。我正在尝试在Angular 5项目中引导多个组件,因此我可以简单地执行以下操作: <body> <awesome-component></awesome-component> <cool-component></cool-component> </body> CoolComponent import { BrowserModule } from "@angular/pla
<body>
<awesome-component></awesome-component>
<cool-component></cool-component>
</body>
CoolComponent
import { BrowserModule } from "@angular/platform-browser";
import { NgModule } from "@angular/core";
import { CoolComponent } from "./cool.component";
@NgModule({
declarations: [CoolComponent],
imports: [BrowserModule],
bootstrap: [CoolComponent]
})
export class CoolModule {}
如果我在main.ts
中引导这些文件,如下所示:
platformBrowserDynamic().bootstrapModule(AwesomeModule);
platformBrowserDynamic().bootstrapModule(CoolModule);
platformBrowserDynamic().bootstrapModule(AwesomeModule);
// platformBrowserDynamic().bootstrapModule(CoolModule);
我在运行ng build
时遇到此错误:
ERROR in Error: Tried to find bootstrap code, but could not. Specify either statically analyzable bootstrap code or pass in an entryModule to the plugins options.
at Object.resolveEntryModuleFromMain (C:\test\node_modules\@ngtools\webpack\src\entry_resolver.js:121:15)
at Promise.resolve.then.then (C:\test\node_modules\@ngtools\webpack\src\angular_compiler_plugin.js:241:54)
at <anonymous>
at process._tickCallback (internal/process/next_tick.js:188:7)
我再次运行ng build
,它运行得很好这里是奇怪的部分:如果我将--watch
添加到ng build
,它将侦听文件更改并生成受影响的文件。如果我使用ONE模块运行ngbuild--watch
,它工作得很好(如我前面所说),但是如果我随后添加第二个模块(删除注释),它就可以构建并工作得很好
所以问题是,我无法用ng build
从头开始构建它,而我的main.ts
文件中有两个模块(带有两个组件)
以前有没有人遇到过这个问题?我把事情搞砸了吗
以下是我的一个组件,仅供参考:
cool.component.ts
import { Component } from "@angular/core";
@Component({
selector: "cool-component",
templateUrl: "./cool.component.html"
})
export class CoolComponent {
public title = "Cool stuff";
}
从
引导-主应用程序视图,称为根组件,承载所有其他应用程序视图。只有根模块应设置此引导属性
您可以创建一个应用程序根目录,并将其放入该应用程序根目录的html中
//index.html
<body>
<app-root>
</body>
//app-root.component.html
<awesome-component></awesome-component>
<cool-component></cool-component>
//index.html
//app-root.component.html
我试图避免使用
组件。这是Angular 4或Angular 5中的一个“新”功能(不确定4是否实现了这一功能)。对不起,我从未听说过这个特性。我写的链接是Angular的实际手册,但事实并非如此。检查:-它是在Angular 5中实现的,所以我不必做你想让我做的事。好吧,我不知道,很抱歉我帮不了你。没问题,请随意删除你的答案:)
//index.html
<body>
<app-root>
</body>
//app-root.component.html
<awesome-component></awesome-component>
<cool-component></cool-component>