cancel
Showing results for 
Search instead for 
Did you mean: 

Magento 2 how to get mage-init data in my custom JS

Magento 2 how to get mage-init data in my custom JS

I have this code in my.phtml:

<script type="text/x-magento-init">
{
"*": {
"installment": <?= $block->getConfig(); ?>
}
}
</script>

I want to get the "parcel" data in my custom Js on the checkout page. How can I get?

When mage-init initializes my widget's _create it returns with the filled data.

When I call requirejs it comes with empty data.

 

define(
[
'ko',
'installation'
],
function (ko, installment) {

help

Alight Motion pro apk is a free motion graphic design editor for mobile devices. It makes the editing process for videos easy, despite the chaotic home screen.
2 REPLIES 2

Re: Magento 2 how to get mage-init data in my custom JS

Hello @ervinjelvo9d3a 

 

Kindly refer below link :
Javascript Init 

 

It may help you!
thank you

Problem solved? Click Accept as Solution!

Re: Magento 2 how to get mage-init data in my custom JS

Hi @ervinjelvo9d3a ,

 

Please refer below link
https://magento.stackexchange.com/questions/290144/magento-2-pass-variable-from-phtml-to-js

 

Below is the simple code that you can use in JS.

From above link you will get full idea about pass data and get data.

 

define([
       'ko',
       'uiComponent'
], function (ko, Component) { 'use strict'; return Component.extend({ /** * @override */ initialize: function () { this._super(); this.maxPrice = ko.observable(this.maxpriceShipping); },
       });
});

 

Problem solved? Click Accept as Solution!

 

Hope it helps!

Thanks

Ankit Jasani