Autogenerating Angular 2 template (with angular directives) -


i want write component autogenerates it's own template. template not plain html has angular tags such ngif, etc. has buttons references (predefined) click handler methods.

i can plain html template autogeneration work using @viewchild ngif getting ignored. (click) handler ref getting ignored.

anyone know how working? thanks!

import {component, viewchild, elementref, afterviewinit} '@angular/core';    @component({    selector: 'app-root',    template: `      <div #formcontainer></div>`,    styleurls: ['./app.component.css']  })  export class appcomponent implements afterviewinit {    title = 'app';    shouldshowlastname : boolean = false;    @viewchild('formcontainer') formcontainer: elementref;      ngafterviewinit(): void {      let formhtml =        `<div id="anchor">            first name:            <input type="text" name="firstname" value="mickey">            <br>            last name:            <input *ngif="shouldshowlastname" type="text" name="lastname" value="mouse">            <br><br>              <button type="button" class="btn btn-lg btn-success" (click)="handlesubmit()">submit</button>        </div>`;        this.formcontainer.nativeelement.innerhtml = formhtml;    }      handlesubmit(){      console.log("submit handler invoked");    }    }


Comments

Popular posts from this blog

ios - MKAnnotationView layer is not of expected type: MKLayer -

ZeroMQ on Windows, with Qt Creator -

unity3d - Unity SceneManager.LoadScene quits application -