Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

ngx-component-outlet

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ngx-component-outlet

NgComponentOutlet + Data-Binding + Full Lifecycle = NgxComponentOutlet for Angular 5, 6+

  • 0.0.8
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
39
increased by116.67%
Maintainers
1
Weekly downloads
 
Created
Source

ngx-component-outlet

Best way to quickly use Dynamic Components with Angular

npm npm License Conventional Commits CircleCI Travis

GitHub contributors GitHub PR Stats GitHub Issue Stats

GitHub stars npm Downloads

Example Usage

Use like NgComponentOutlet but with @Input/@Output auto bindings:

<!-- host component -->
<app-dynamic
    <!-- dynamic component -->
    [ngxComponentOutlet]="component"
    <!-- regular input -->
    [entity]="entity"
    <!-- regular output -->
    (action)="onAction($event)">
</app-dynamic>

Comparison

FeatureNgxComponentOutletComponentFactoryResolverNgComponentOutlet
Friendliness⭐⭐⭐⭐⭐
Dynamic Components
AOT support
Reactivity
Injector
NgModule
projectionNodes
Component Access
Lifecycle OnChanges⭕️ manually
Binding @Input()⭕️ manually
Binding @Output()⭕️ manually
Activate Event⭕️ manually
Deactivate Event⭕️ manually

Demo

Heroes

List of heroes

Table And Form

Table of heroes with table schema form

Editable Demo

Stackblitz

Github

Getting started

Step 1: Install ngx-component-outlet:

NPM
npm install --save ngx-component-outlet
Yarn
yarn add ngx-component-outlet

Step 2: Import the NgxComponentOutletModule:

import { NgxComponentOutletModule } from 'ngx-component-outlet';

@NgModule({
  declarations: [ AppComponent ],
  imports: [ NgxComponentOutletModule.forRoot() ],
  bootstrap: [ AppComponent ]
})
export class AppModule {}

Step 3: Create components that your want to use dynamically:

@Component({
    selector: 'app-dynamic-comp-a',
    template: `I'm Dynamic Component A. Hello, {{ name }}!`
})
export class CompAComponent {
    @Input() name: string;
}
@Component({
    selector: 'app-dynamic-comp-b',
    template: `I'm Dynamic Component B. Hello, {{ name }}!`
})
export class CompBComponent {
    @Input() name: string;
}

Step 4: Add components to declarations and entryComponents:

@NgModule({
    ...
    declarations: [ ..., CompAComponent, CompBComponent ],
    entryComponents: [ CompAComponent, CompBComponent ]
})
export class AppModule {}

Step 5: Create a host component with the same inputs/outputs:

@Component({
    selector: 'app-host-for-dynamic',
    template: ''
})
export class HostComponent {
    @Input() name: string;
}

Step 6: Add the component to declarations:

@NgModule({
    ...
    declarations: [ ..., HostComponent ],
    ...
})
export class AppModule {}

Step 7: Now show dynamic component in AppComponent:

import { Component } from '@angular/core';

@Component({
    selector: 'app-root',
    template: `
        <app-host-for-dynamic [ngxComponentOutlet]="componentA"
          [name]="'Angular 5!'"></app-host-for-dynamic>
        
        <app-host-for-dynamic [ngxComponentOutlet]="componentB"
          [name]="'Angular 6?'"></app-host-for-dynamic>
    `
})
export class AppComponent {
    componentA = CompAComponent;
    componentB = CompBComponent;
}
And you will have in AppModule:
import { NgxComponentOutletModule } from 'ngx-component-outlet';

@NgModule({
  imports:      [ NgxComponentOutletModule.forRoot() ],
  declarations: [ AppComponent, CompAComponent, CompBComponent, HostComponent ],
  entryComponents: [ CompAComponent, CompBComponent ],
  bootstrap:    [ AppComponent ]
})
export class AppModule {}

API

InputTypeDefaultRequiredDescription
[ngxComponentOutlet]Type<any>n/ayes
[ngxComponentOutletInjector]Injectorn/ano
[ngxComponentOutletContent]any[][]n/ano
[ngxComponentOutletNgModuleFactory]NgModuleFactory<any>n/ano
OutputTypeDescription
(ngxComponentOutletActivate)any
(ngxComponentOutletDeactivate)any

Advanced Use Cases

Here is a demo repository showing ngx-component-outlet and Angular in action.

Keywords

FAQs

Package last updated on 10 Jun 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc