Render content anywhere in your angular app in a declarative manner. Render DOM outside of a component, anywhere in your app!
<!--This can be anwhere in your App-->
<ngx-teleport to="destination"> <stuff>...</stuff></ngx-teleport>
<!--This can be anwhere in your App-->
<ngx-teleport-outlet name="destination"> </ngx-teleport-outlet>
<!--content will be rendered here-->
<stuff>...</stuff>
View Source 路 Report Bug 路 Request Feature
馃殌 聽 Declarative 路 馃帀 聽 Very Simple to use 路 馃嵒 聽 No Auxilary Routing 路 馃挌 聽 No Imperative Portal Creation and Lifecycle Management
Table of Contents
There are many situations where we would want to break the unidirectional top-down rendering of template/components and render DOM outside of a component, anywhere in your app
Here are few use cases:
- You want to render different template in your toolbar or sidebar based on different routes but you want to bind properties and events in the child component
- You want to conditionally show some template in different corners of your application which may not be hierarchically related
Use the NgxTeleport
to get started.
npm install ngx-teleport
or using yarn
yarn add ngx-teleport
<!--This can be anwhere in your App-->
<ngx-teleport to="destination"> <stuff>...</stuff></ngx-teleport>
<!--This can be anwhere in your App-->
<ngx-teleport-outlet name="destination"> </ngx-teleport-outlet>
<!--content will be rendered here-->
<stuff>...</stuff>
- Just Import
NgxTeleportModule
in the NgModule of which ever components you are usingngx-teleport
andngx-teleport-outlet
in
import { NgxTeleportModule } from 'ngx-teleport';
@NgModule({
//...
imports: [
//..
NgxTeleportModule,
//..
],
})
export class SomeModule {}
For more examples, please refer to the Documentation
Contributions are what make the open source community such an amazing place to learn, inspire, and create. Any contributions you make are greatly appreciated.
If you have a suggestion that would make this better, please fork the repo and create a pull request. You can also simply open an issue with the tag "enhancement". Don't forget to give the project a star! Thanks again!
- Fork the Project
- Create your Feature Branch (
git checkout -b feature/AmazingFeature
) - Commit your Changes (
git commit -m 'Add some AmazingFeature'
) - Push to the Branch (
git push origin feature/AmazingFeature
) - Open a Pull Request
Distributed under the MIT License. See LICENSE.md
for more information.
Nivrith - @_Nivrith_ - [email protected]
Project Link: https://github.com/nivrith/ngx-teleport