Not able to receive data on child (modal) component

This is regarding custom apps. Actually the problem is, am not able to get the passing data on child component.

This is React.js custom app, Which has parent file index.html and child (modal.html)

Am using below interface method to trigger child (modal.html) component from parent component

client.interface.trigger('showModal', {
title: 'Sample Modal',
template: 'modal.html',
data: { firstName: 'John', lastName: 'Doe' },
})

And am trying to get the passed data on child component by below method
Note: I have added this code in app/modal.html → Inside script element

window?.client?.instance?.context().then(function (context) {
console.log('Passing-parameters', context);
})
  • I wasn’t not able to get the passed data in the child component. I was getting error “Client is not defined”.
    Note: I have added this script on head ("https://static.freshdev.io/fdk/2.0/assets/fresh_client.js)

  • I have tried to set the client on localStorage. But that doesn’t have context in it.

Hi Bharath

Good day!

Welcome to the freshworks developer community :slightly_smiling_face:

You first need to initialise the client object before using it

document.addEventListener("DOMContentLoaded", function () {
  app.initialized()
    .then(function (_client) {
      window.client = _client;
      client.instance.context()
        .then(function (context) {
          console.log(context.data);
        })
        .catch(function (error) {
          console.error('error', error);
        });
    });
});

For more samples please refer here

2 Likes

Thanks for the response Banu. It worked.

If you don’t mind, Could you let me know that which event or method gets invoked while clicking custom app icon ?
Lets consider the icon location is “ticket_top_navigation”

Thanks

Hi Bharath

When you tell ‘clicking the custom app icon’ you mean to say when you open / expand the app by clicking the corresponding icon right? In that case app.activated would be triggered.

For more info regarding the events please refer here ( Check the section under app/app.js )

1 Like

Thanks for the update Banu

This topic was automatically closed 6 days after the last reply. New replies are no longer allowed.