Code Monkey home page Code Monkey logo

Comments (4)

jstechaut avatar jstechaut commented on May 24, 2024 1

I want the data to be passed without closing the modal , as close event will only work on closing the modal , I want to send data back to parent component without closing the modal

from primeng.

renanhfranca avatar renanhfranca commented on May 24, 2024

Hi jstechaut,

In my project, when I'm working with Dynamic Dialog, I use the close method to pass data back to the parent. Basically, inside the opened component, I inject the DynamicDialogRef reference. Then, on the close button, I call the close method, passing the data. In the parent component, it is necessary to subscribe to the onClose event.

You can find a sample on the link bellow:

https://primeng.org/dynamicdialog

from primeng.

NateRadebaugh avatar NateRadebaugh commented on May 24, 2024

You can write a small function to have a promise that only resolves once the dialog is closed:

export async function showModalDialogWithRef(dialogService, content, data) {
  const dialogRef = dialogService.open(content, {
    // your options
    data: {
      ...data,
    },
  });

  return new Promise((resolve, reject) => {
    dialogRef.onClose.subscribe((result) => {
      resolve(result);
    });
  });
}

Or you can return the reference in case you need to use it to dynamically close later

export async function showModalDialogWithRef(dialogService, content, data) {
  const dialogRef = dialogService.open(content, {
    // your options
    data: {
      ...data,
    },
  });

  // Properly bind the context of the dialog so we can close it dynamically
  dialogRef.close = dialogRef.close.bind(dialogRef);

  return [
    new Promise((resolve, reject) => {
      dialogRef.onClose.subscribe((result) => {
        resolve(result);
      });
    }),
    dialogRef,
  ] as const;
}

from primeng.

NateRadebaugh avatar NateRadebaugh commented on May 24, 2024

Interesting. Try passing the callback as part of the data object then, and you can call it from your modal directly.

from primeng.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.