0

Using php REST, I am getting html in json from php server.

I used to simply use innerhtml to display the html in angular.

However, I need to add the html component to the angular component instead

main.ts

import { my_component } from './my_component';

@Component({
    selector: 'page-main_page',
    templateUrl: 'main_page.html'
})
export class main_page {        
    data: any;

constructor(public mine: my_component ){    

};      

    ngOnInit(){ 
        this.getDynamicREST().then((res)=>{

          //where res is "<div class="test">Test</div>"

          //????              

        })
    };

}

my_component.ts

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

@Component({
    selector: 'my_component ',
    template: '????' // HTML json goes here
})

export class my_component {
   data: any;
}

How would I achieve this so that I can fetch angular components dynamically and add them to the my_component.ts template?

Any help will be much appreciated.

Thank you.

Steve Kim
  • 5,293
  • 16
  • 54
  • 99
  • In my solution to this question: https://stackoverflow.com/questions/48753464/angular-how-to-use-reactive-forms-in-a-dynamic-component I have a StackBlitz that shows how to create dynamic components. Hopefully that will help you get to what you need. – Narm Feb 28 '18 at 19:53
  • Thanks! I will take a look at it! =) Much appreciated – Steve Kim Feb 28 '18 at 20:11

0 Answers0