0

I have created a component "test" with Ionic 2 CLI, and was wondering how do I add this component dynamically to the #componentContainer HomePage from HomePage.ts.

Here is test component:

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

@Component({
  selector: 'test',
  templateUrl: 'test.html'
})
export class TestComponent {

  text: string;

  constructor() {
    console.log('Hello TestComponent Component');
    this.text = 'Hello World';
  }
}

And here is my HomePage:

<ion-content padding>
      <div #componentContainer>

      </div>
</ion-content>

Here is the HomePage.ts

import { Component, ViewChild, ViewContainerRef, ComponentFactoryResolver} from '@angular/core';
import { NavController } from 'ionic-angular';

@Component({
  selector: 'page-home',
  templateUrl: 'home.html'
})
export class HomePage {

  constructor(public navCtrl: NavController) {

  }

  ngOnInit() {

  }
}

Can't find the answer anywhere...

Christer
  • 2,746
  • 3
  • 31
  • 50
  • 1
    Try to follow these links http://blog.rangle.io/dynamically-creating-components-with-angular-2/ http://plnkr.co/edit/ZXsIWykqKZi5r75VMtw2?p=preview https://stackoverflow.com/a/40571013/4667424 – CharanRoot Jun 19 '17 at 19:58
  • Why you need to add it from HomePage.ts. You can do with tag `` – Duannx Jun 20 '17 at 02:30
  • Thanks for the link Jonnysai, that was what I needed :) – Christer Jun 20 '17 at 06:24

0 Answers0