Joe Scotto
Joe Scotto

Reputation: 10887

Ionic dynamic component creation?

Is there a way using Ionic to dynamically create a component? For example, I have a few pages where a login prompt should be displayed. I have my component added to my module but don't know where I should go next in order to get this to display when certain events are called.

Any help as to where I should go now, I'm super confused on what I should do.

Upvotes: 0

Views: 1073

Answers (2)

Ari
Ari

Reputation: 7556

I suggest two options:

  1. Show a new page using ionic tabs, modal, or push and put social login control on all of them.
  2. Use a single component, and put each page that you wanna show in an Ionic slides or div, and then only show the page that is relevant (using slideTo for slides or *ngIf for div). The social login can be added outside of the slides/div so it would be visible in all pages. You can put it in a footer.

Upvotes: 1

sic-sic
sic-sic

Reputation: 182

Since you have the LoginPage added to your module. You can use Ionic built-in ModalController to popup your login page everywhere you need it.

Here is an example:

export class MyPage {
    constructor(public modalCtrl: ModalController) {
    }

    presentModal() {
        let modal = this.modalCtrl.create(LoginPage);
        modal.present();
    }
}

Source: https://ionicframework.com/docs/components/#modals

Upvotes: 0

Related Questions