Inspecting some code from my project, I've encountered a strange scenario in which I think Angular should throw an error at build time.
In my Angular app I have this index.html file with all the required code and my app selector
html head body my-root-app-selector
My main.ts file is bootStrapping AppModule.
My app.module.ts has the following code:
@NgModule({
declarations: [AppComponent1, AppComponent2],
imports: [BrowserModule],
})
export class AppModule implements DoBootstrap {
ngDoBootstrap(appRef: ApplicationRef) {
if(conditionTrue) {
appRef.bootstrap(AppComponent1);
}
appRef.bootstrap(AppComponent2);
}
}
My issue is that both components share the same selector:
my-root-app-selector
All the Angular documentation points towards that there should not be any components that shares the same selector, but even so, Angular doesn't have any problem with this code.
What am I missing here?
I've created a StackBlitz to replicate my issue: https://shorturl.at/9T87G
AppComponent2andAppComponent1in the declarations array of app module and you will get the error.[AppComponent1, AppComponent2]