File

projects/rebirth-ng/src/lib/common/template-loader.component.ts

Implements

OnInit OnDestroy

Metadata

selector re-template-loader

Index

Properties
Methods
Inputs

Constructor

constructor(viewContainer: ViewContainerRef)
Parameters :
Name Type Optional
viewContainer ViewContainerRef no

Inputs

$implicit

Type: any

Default value: {}

data

Type: any

template

Type: TemplateRef<any>

Methods

ngOnDestroy
ngOnDestroy()
Returns : void
ngOnInit
ngOnInit()
Returns : void

Properties

view
view: EmbeddedViewRef<any>
Type : EmbeddedViewRef<any>
Public viewContainer
viewContainer: ViewContainerRef
Type : ViewContainerRef
import { Component, OnInit, OnDestroy, TemplateRef, Input, EmbeddedViewRef, ViewContainerRef } from '@angular/core';

@Component({
  selector: 're-template-loader',
  template: ``
})
export class TemplateLoaderComponent implements OnInit, OnDestroy {

  @Input() template: TemplateRef<any>;
  @Input() data: any;
  @Input() $implicit: any = {};

  view: EmbeddedViewRef<any>;

  constructor(public viewContainer: ViewContainerRef) {

  }

  ngOnInit() {
    if (this.template) {
      const context = Object.assign({}, { '$implicit': this.data }, this.data);
      this.view = this.viewContainer.createEmbeddedView(this.template, context);
    }
  }

  ngOnDestroy() {
    if (this.view) {
      this.view.destroy();
    }
  }
}
Legend
Html element
Component
Html element with directive

results matching ""

    No results matching ""