Comments (9)
Hi, is there a reason you're using createComponent
+ applicationRef.attachView
instead of viewContainerRef.createComponent
. Because there is no issue in the latter.
from angular.
Hi, is there a reason you're using
createComponent
+applicationRef.attachView
instead ofviewContainerRef.createComponent
. Because there is no issue in the latter.
Yes
from angular.
What would be the particular usecase your are looking to address with this?
from angular.
Closing as expected. This is effectively the same thing as having two router outlets.
from angular.
Note that as @atscott mentions, this is effectively replacing the primary router outlet, as it's created as a root-level outlet.
To create it as a child outlet of the root outlet instead, you would need to create the new component as a DI child of the parent RouterOutlet
. This is done by passing elementInjector
as well as environmentInjector
when calling createComponent
. See: https://stackblitz.com/edit/ng-create-component-with-outer-outlet-gzentc?file=src%2Fdashboard.ts
from angular.
@alxhub @atscott @JeanMeche thank you very much for providing the solution.
- Firstly, the current expectation is for version 16.0 to appear, in 15.x it don't replace the primary router outlet, it looks like a breaking change.
- We are using
createComponent
+applicationRef.attachView
when using a micro front-end for cross application rendering, App1 renders component of another application (App2), App1 can only obtain theapplicationRef
of App2, IfelementInjector
can be passed, then simply useviewContainerRef.createComponent
instead of the globalcreateComponent
. - If this is a expected behavior, are there other alternative solutions besides passing
elementInjector
.
from angular.
Firstly, the current expectation is for version 16.0 to appear, in 15.x it don't replace the primary router outlet, it looks like a breaking change.
Your example seems to have the same behavior in 15: https://stackblitz.com/edit/angular-3eqbcp
App1 renders component of another application (App2), App1 can only obtain the applicationRef of App2
This seems a bit sketchy. Why is this the case and why aren't the ApplicationRef
instances the same? Regardless, I'm not really following why App1 cannot create the App2 component and always pass the elementRef
so that the ElementRef
hierarchy is preserved for RouterOutlet
. This is required to avoid same-name collisions of outlets.
If this is a expected behavior, are there other alternative solutions besides passing elementInjector.
There should be other workarounds. For example, preventing App2 from rendering another outlet with the same name.
from angular.
Your example seems to have the same behavior in 15: https://stackblitz.com/edit/angular-3eqbcp
Sorry for my mistake, i only test it use NgModule in 15 : https://stackblitz.com/edit/angular-3tn8ws, I didn't expect that standalone component application would be inconsistent with NgModule app.
This seems a bit sketchy. Why is this the case and why aren't the ApplicationRef instances the same? Regardless, I'm not really following why App1 cannot create the App2 component and always pass the elementRef so that the ElementRef hierarchy is preserved for RouterOutlet. This is required to avoid same-name collisions of outlets.
App1 and App2 are different angular application, they all have independent AppModule and router. I found this issue is due to using the example of @worktile/planet
, I open http://planet.ngnice.com/app1/projects after the page, when navigate to App2 again, a blank page appears:
because the /app1/projects
page renders a component of App2, and the component template of App2 includes a router-outlet.
There should be other workarounds. For example, preventing App2 from rendering another outlet with the same name.
I think this is a good idea
from angular.
This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.
Read more about our automatic conversation locking policy.
This action has been performed automatically by a bot.
from angular.
Related Issues (20)
- Recursive template with @defer HOT 3
- The output-function page is not accessible https://angular.dev/guide/output-function
- developer preview features HOT 2
- toSignal causes the signal to not being lazy-evaluated HOT 6
- API for ngModule bootstrap for SSR? - `platformServer.bootstrapModule` vs `bootstrapApplication` of `@angular/platform-server`? HOT 2
- Renderer2 method that allows you to set signal inputs HOT 5
- Angular attributes produce HTML validation errors HOT 3
- Angular 15 - router.events are empty with nested router outlets on page refresh HOT 1
- The CSP nonce remains in the DOM after being read by Angular HOT 1
- API Reference search on angular.dev HOT 3
- Improve the angular.dev dark mode HOT 1
- Use hadError instead of errors
- docs: @defer requires the parent component also be standalone
- BrowserViewportScroller not honoring native scroll margin HOT 4
- Unit Testing guide has incorrect code HOT 1
- Angular compiler seemingly false negative warning : optional chaining refused on array item HOT 3
- ActivatedRoute in Directive: Snapshot.params are not getting updated HOT 2
- APP_INITIALIZER with HttpClient provoke memory leak in SSR projects HOT 8
- New Angular Docs website is not PWA compatible
- @for can't be used for forms where $index based calls on removeAt() are necessary HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from angular.