How to load a modal in Ionic 4

General Tech Bugs & Fixes 2 years ago

1 2 0 0 0 tuteeHUB earn credit +10 pts

5 Star Rating 1 Rating

Posted on 31 Aug 2022, this text provides information on Bugs & Fixes related to General Tech. Please note that while accuracy is prioritized, the data presented might not be entirely correct or up-to-date. This information is offered for general knowledge and informational purposes only, and should not be considered as a substitute for professional advice.

Take Quiz To Earn Credits!

Turn Your Knowledge into Earnings.

tuteehub_quiz

Answers (2)

Post Answer
profilepic.png
manpreet Tuteehub forum best answer Best Answer 2 years ago

 

I have an index that i have a add button when press load a modal.

index.html


  
    Foods
    
      
        
      
    
  

this is the index page ts

import { Component } from '@angular/core';
import { ModalController } from '@ionic/angular';
import { AddPage } from '../add/add.page';

@Component({
  selector: 'app-index',
  templateUrl: 'index.page.html',
  styleUrls: ['index.page.scss']
})
export class IndexPage {

  constructor(private modalController: ModalController) { }

  async showModal() {
    const modal = await this.modalController.create({
      component: AddPage,
    });
    await modal.present();
  }
}

so when the user click showModal load the modal.

Now this is my add modal module.

import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { FormsModule } from '@angular/forms';
import { Routes, RouterModule } from '@angular/router';

import { IonicModule } from '@ionic/angular';

import { AddPage } from './add.page';

const routes: Routes = [
  {
    path: '',
    component: AddPage
  }
];

@NgModule({
  imports: [
    CommonModule,
    FormsModule,
    IonicModule,
    RouterModule.forChild(routes)
  ],
  declarations: [AddPage]
})
export class AddPageModule {}

This is my add page td.

import { Component, OnInit } from '@angular/core';
import { NavParams } from '@ionic/angular';

@Component({
  selector: 'app-add',
  templateUrl: './add.page.html',
  styleUrls: ['./add.page.scss'],
})
export class AddPage implements OnInit {

  constructor() {

  }

The problem when i go to the index page the Modal is already loaded. I can't even see the Index page anymore. Its like the Modal is being routed to the Index page.

profilepic.png
manpreet 2 years ago

In your modal html, add the following:



Foods

  color="primary" (click)="dismissModal()"> Dismiss
  
  
 

 

Then in the ts, add the following:

dismissModal() {
 this.modalController.dismiss(null);
}

This will let you dismiss the open modal.


1 views   0 shares

No matter what stage you're at in your education or career, TuteeHub will help you reach the next level that you're aiming for. Simply,Choose a subject/topic and get started in self-paced practice sessions to improve your knowledge and scores.

tuteehub community

Join Our Community Today

Ready to take your education and career to the next level? Register today and join our growing community of learners and professionals.

tuteehub community