Skip to content

AlanD3/inyector

Repository files navigation

npm version NPM Bundle Size Download

Inyector

Angular service for component injection

Installation

npm install inyector --save

Demo

You can see the demo in https://inyector.netlify.com/

Usage

Import

import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { InyectorModule } from 'inyector';

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

Inject component in body

this.inyector.add(TestComponent);

Inject component in an element

this.inyector.add(TestComponent, {
    parent: htmlElement
});

Floating injection

Inject component in a floating docker and attach it to another element

this.inyector.dock(TestComponent, parentHtmlElement, {
    position: 'top'
});