Issue with Ionic 3 modal: Navparams coming back as undefined

I'm currently facing an issue where I am passing a string as a parameter to a Modal (specifically a master/detail modal) and although the Modal opens successfully, the string is being returned as undefined.

Below is the TypeScript code for the parent component:

 editReminder(event, data){
    console.log(data);
    let myModal = this.modalCtrl.create(ReminderDetailsPage, data);
    myModal.present();
}

The HTML file displays a list of reminders using ngFor (reminder of reminders). The parameter 'data' is passed like this in the HTML:

 <button ion-fab mini class="mini-button" (click)="editReminder($event, reminder)">
          <ion-icon name="create"></ion-icon>
 </button>

When I console.log(data), it correctly logs the reminder. However, when trying to retrieve it in the ReminderDetails modal:

export class ReminderDetailsPage {

   EditedReminder: string = this.navParams.get('data');

It returns undefined. Both pages have imported navParams and declared them in the constructor.

Answer №1

this.modalCtrl.create(ReminderDetailsPage, { info: information });

Provide a data object to the create() function. Retrieve the data using navParams.get() either in the constructor or within a lifecycle method such as ngOnInit.

Answer №2

When working with a Modal page

ionViewWillLoad() {
 const content = this.navParams.get('content');
 console.log(content);
}

To send data back from the modal...

import {NavParams, ViewController} from 'ionic-angular';
...
    content: String
     constructor(private navParams: NavParams, private view: ViewController) {}
    ionViewWillLoad() {
     this.content = this.navParams.get('content');
     console.log(this.content);
    }

  closeModal() {
    this.view.dismiss(content);
  }

In your main calling page:

 const myModal: Modal = this.model.create('ModalPage', {content: myContent})
 myModal.present();
 myModal.onWillDimiss(data) => {
     console.log(`About to dismiss with: ${data}`);
 })
 myModal.onDidDimiss(data) => {
     console.log(`Dismissed with: ${data}`);
 })

Answer №3

If that's the situation, my recommendation is to opt for utilizing storage instead of NavParams.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Retrieve the component when there is a change in the variable in Angular versions greater than 4

When invoking the ngx-ebar-treemo component in my main component, I use the following syntax: <ngx-ebar-treemo *ngIf="type=='Bar' && graphic" type1="{{type1}}" type2="{{type2}}"></ngx-ebar-treemo> I need to call this compone ...

Module import in Ionic

I'm encountering an issue with Ionic, Angular, and TypeScript, and I'm feeling a bit lost... I'm trying to call an external function from my file but I keep getting the following error: "Uncaught (in promise): TypeError: undefined is not an ...

Reducing image file sizes in Ionic 3

I have been struggling to compress an image client-side using Ionic 3 for the past couple of days. I have experimented with: ng2-img-max - encountered an error when utilizing the blue-imp-canvas-to-blob canvas.toBlob() method (which is a dependency of ng2 ...

Angular2 Dynamic Forms: Unveiling Fields Conditionally

When using dynamic forms, I want to display a field only when another field has a specific value. In order to achieve this, I added a new property called "condition: boolean" to the QuestionBase class (app/question-base.ts). This property will determine w ...

What is the best way to incorporate my own custom component into the Mui Theme options in order to efficiently modify it?

I've been grappling with this issue for a while now and I just can't seem to get past these type errors. It feels like there's a crucial piece of the puzzle that I'm missing. My goal is to develop my own custom component and then have ...

Utilize a singular loader when simultaneously making numerous HTTP requests in Angular with ngx-ui-loader

After successfully implementing the ngx-ui-loader and setting the NgxUiLoaderHttpModule for all HTTP requests in my project, everything is working fine. However, I have encountered an issue on certain routes where multiple HTTP requests are being executed ...

In the context of Expo and TypeScript, the error message "Type '{}' does not have property 'origin'" appears

When attempting push notifications in expo react native, I encountered an error. I am using TypeScript. This is the code I used: The error message indicates that "Property 'origin' does not exist on type '{}'.", and the same for ' ...

Issue with Angular 12 Chart.js: Doughnut chart not rendering

I've successfully managed to display a line graph and a bar chart, but for some reason, I'm struggling to display a pie chart or a doughnut chart. Despite going through several tutorials and attempting different solutions, I still can't seem ...

Converting data types in TypeScript function parameters

Modify a function's parameter type by forcefully casting it. In the scenario displayed below: (<number>foo)(1) The original function definition is as follows: function foo( v : string ) ...

How can I validate a method for formGroup in Angular 2?

Below is a form I am working with: this.changePasswordForm = this.formBuilder.group({ 'passwordNew': ['', ValidationService.passwordValidator], matchingPasswords('passwordNew', 'passwordNewConfirmation')(this) ...

The functionality of 'ngbPopover' in Ng-bootstrap may be affected if the parent container contains a 'transform' css property

Struggling to implement Ng-bootstrap's 'ngbPopover' functionality, I encountered a frustrating issue where the popover would not display after clicking the button. After numerous hours of troubleshooting, I was relieved to discover the root ...

How can TypeScript associate enums with union types and determine the type of the returned object property?

I have a unique enum in conjunction with its corresponding union type. type User = { name: string, age: number } export enum StorageTypeNames { User = "user", Users = "referenceInfo", IsVisibleSearchPanel = "searchPane ...

How can we update a boolean value in an Angular service using a set function?

Hey there! I'm currently working on updating a boolean value in my service when a button is clicked within my component. My goal is to trigger the setfunction and toggle the boolean value from true to false, and vice versa when the button is clicked a ...

How can a custom event bus from a separate account be incorporated into an event rule located in a different account within the CDK framework?

In account A, I have set up an event rule. In account B, I have a custom event bus that needs to act as the target for the event rule in account A. I found a helpful guide on Stack Overflow, but it was specific to CloudFormation. I am providing another a ...

JavaScript module declarations in TypeScript

Recently, I delved into the world of a Node library known as bpmn-js (npmjs.com). This library is coded in JavaScript and I wanted to incorporate typings, which led me to explore d.ts files. My folder structure looks like this webapp @types bpmn ...

Tips for incorporating state properties into a component

Currently engrossed in a project revolving around state management for individual components utilizing Angular 7 and NGRX. The challenge at hand is to ensure scalability of the implementation, allowing multiple uses while maintaining independence. Thus fa ...

Guidelines for incorporating Dropdown menus in a Multi-level Carousel themed SideNav using Angular 5 Material

https://i.sstatic.net/cbmuA.gif Hey there, World! I've been working on a sidenav with tabs that has the perfect transition effect I was looking for. Now, I want to add functionality so that when users click on "Option 1, Option 2 or Option 3", the tab ...

Typically used to describe an item with a variable amount of string attributes

I have a TypeScript generic for an object with an unspecified number of string parameters like this: type Params<T extends string[]> = Record<T[number], string>; However, every time I want to use it, I need to define it with an array like so: ...

Challenges encountered while running the npm start command

I'm diving into some Angular tutorials and having trouble getting npm to run on OSX Yosemite. Here's the error log. I've followed the instructions, but still can't view the compiled app at localhost:3000. 0 info it works if it ends wi ...

Troubleshooting ngFor in Angular 5

I'm currently working on a component that needs to display data fetched from the server. export class CommerceComponent implements OnInit { dealList; ngOnInit() { this.getDeals(); } getDeals(){ this.gatewayService.se ...